New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parent helpers inside helper #1783

Closed
whitecolor opened this Issue Jul 14, 2015 · 11 comments

Comments

Projects
None yet
4 participants
@whitecolor
Contributor

whitecolor commented Jul 14, 2015

I need to create helper that will return template stache fragment and insert it in DOM, so I do:

helpers: {
    someTemplateHelper: function(options){
            var template = '<my-comp"></my-comp>'
            return can.stache(template)(options.contexts)
    }
}

The parent context are passed to stache fragment, but not helpers (options do not contain helpers). Is it possible to access parent helpers and render template that can access them?

@matthewp

This comment has been minimized.

Show comment
Hide comment
@matthewp

matthewp Jul 14, 2015

Contributor

Could probably be added here

Contributor

matthewp commented Jul 14, 2015

Could probably be added here

@whitecolor

This comment has been minimized.

Show comment
Hide comment
@whitecolor

whitecolor Jul 14, 2015

Contributor

Yes this works if we do:

                can.simpleExtend(helperOptions, {
                    context: context,
                    scope: scope,
                    contexts: scope,
                    hash: hash,
                    nodeList: nodeList,
                    exprData: exprData,
                    helpers: options // added here
                });

An then we can do:

return can.stache(template)(options.contexts, options.helpers)

Should it be done this way? or add in mustache_core:

options: options
Contributor

whitecolor commented Jul 14, 2015

Yes this works if we do:

                can.simpleExtend(helperOptions, {
                    context: context,
                    scope: scope,
                    contexts: scope,
                    hash: hash,
                    nodeList: nodeList,
                    exprData: exprData,
                    helpers: options // added here
                });

An then we can do:

return can.stache(template)(options.contexts, options.helpers)

Should it be done this way? or add in mustache_core:

options: options
@matthewp

This comment has been minimized.

Show comment
Hide comment
@matthewp

matthewp Jul 15, 2015

Contributor

Doesn't options contain more than just helpers? If so I think options is what it should be called.

Contributor

matthewp commented Jul 15, 2015

Doesn't options contain more than just helpers? If so I think options is what it should be called.

@whitecolor

This comment has been minimized.

Show comment
Hide comment
@whitecolor

whitecolor Jul 16, 2015

Contributor

well its structure is:

__cache: ..
__context: {
   helpers: ..
   tags: ...
 }
_parent: ..

It is better look yourself.

Contributor

whitecolor commented Jul 16, 2015

well its structure is:

__cache: ..
__context: {
   helpers: ..
   tags: ...
 }
_parent: ..

It is better look yourself.

@whitecolor

This comment has been minimized.

Show comment
Hide comment
@whitecolor

whitecolor Jul 21, 2015

Contributor

@justinbmeyer have you seen that?

Contributor

whitecolor commented Jul 21, 2015

@justinbmeyer have you seen that?

@whitecolor

This comment has been minimized.

Show comment
Hide comment
@whitecolor

whitecolor Jul 22, 2015

Contributor

@matthewp any comment on that?

Contributor

whitecolor commented Jul 22, 2015

@matthewp any comment on that?

@justinbmeyer

This comment has been minimized.

Show comment
Hide comment
@justinbmeyer

justinbmeyer Jul 22, 2015

Contributor

It does contain more then helpers. I really don't have a good name for this. For now, we might pass it as helpers and options but don't document it until 3.0. With 3.0 we need to decide what the names of these things are. Personally, I'm not sure the "helpers" should even exist. It should just be something on the root of every template ... but on the normal scope chain. No reason to have 2.

Contributor

justinbmeyer commented Jul 22, 2015

It does contain more then helpers. I really don't have a good name for this. For now, we might pass it as helpers and options but don't document it until 3.0. With 3.0 we need to decide what the names of these things are. Personally, I'm not sure the "helpers" should even exist. It should just be something on the root of every template ... but on the normal scope chain. No reason to have 2.

@whitecolor

This comment has been minimized.

Show comment
Hide comment
Contributor

whitecolor commented Jul 22, 2015

@matthewp

This comment has been minimized.

Show comment
Hide comment
@matthewp

matthewp Jul 22, 2015

Contributor

Pass it as both.

options: options,
helpers: options
Contributor

matthewp commented Jul 22, 2015

Pass it as both.

options: options,
helpers: options
@asavoy

This comment has been minimized.

Show comment
Hide comment
@asavoy

asavoy Jul 23, 2015

Contributor

+1 I've run into this as well

Contributor

asavoy commented Jul 23, 2015

+1 I've run into this as well

@whitecolor

This comment has been minimized.

Show comment
Hide comment
@whitecolor

whitecolor Jul 23, 2015

Contributor

should it go to master or minor?

Contributor

whitecolor commented Jul 23, 2015

should it go to master or minor?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment