Pass local helpers to sub templates. #734

Closed
honzatrtik opened this Issue Feb 10, 2014 · 6 comments

Comments

Projects
None yet
4 participants
@honzatrtik

I need to add rendered element to context (can.Map instance). I am able to accomplish this using {{(el) -> scope._context.attr('element', el)}} but it seems to be ugly...

@honzatrtik

This comment has been minimized.

Show comment
Hide comment
@honzatrtik

honzatrtik Feb 10, 2014

Also tried to save element to context via helper,

saveElementToContext: function(hash) {
        return function(element) {
            hash.context.attr('element', element);
        };
    } 

but it fails when using nested mustache templates (while rendering tree list structure) like this:

<ul>
    {{#children}}
    <li {{saveElementToContext}}>{{name}}
        {{> controls/menu/menu}}
    </li>
    {{/children}}

</ul>

probably because helper function is called after template is rendered into DOM and somehow nested templates dont call the helper.

Also tried to save element to context via helper,

saveElementToContext: function(hash) {
        return function(element) {
            hash.context.attr('element', element);
        };
    } 

but it fails when using nested mustache templates (while rendering tree list structure) like this:

<ul>
    {{#children}}
    <li {{saveElementToContext}}>{{name}}
        {{> controls/menu/menu}}
    </li>
    {{/children}}

</ul>

probably because helper function is called after template is rendered into DOM and somehow nested templates dont call the helper.

@justinbmeyer

This comment has been minimized.

Show comment
Hide comment
@justinbmeyer

justinbmeyer Feb 10, 2014

Contributor

@honzatrtik Can you make a fiddle showing the helper does not work?

Contributor

justinbmeyer commented Feb 10, 2014

@honzatrtik Can you make a fiddle showing the helper does not work?

@honzatrtik

This comment has been minimized.

Show comment
Hide comment
@honzatrtik

honzatrtik Feb 10, 2014

http://jsfiddle.net/VVQ8k/1/

please, check the console.log output - only first level nodes have element attribute...

http://jsfiddle.net/VVQ8k/1/

please, check the console.log output - only first level nodes have element attribute...

@justinbmeyer

This comment has been minimized.

Show comment
Hide comment
@justinbmeyer

justinbmeyer Feb 10, 2014

Contributor

This is a problem with mustache helpers not being passed to a sub-template. If you make the helper global it works like it does here:

http://jsfiddle.net/VVQ8k/3/

Can I change the issue to more accurately reflect the problem?

Contributor

justinbmeyer commented Feb 10, 2014

This is a problem with mustache helpers not being passed to a sub-template. If you make the helper global it works like it does here:

http://jsfiddle.net/VVQ8k/3/

Can I change the issue to more accurately reflect the problem?

@honzatrtik

This comment has been minimized.

Show comment
Hide comment
@honzatrtik

honzatrtik Feb 10, 2014

I see! Thank you very much, Justin! Yes, change the issue subject, please.

I see! Thank you very much, Justin! Yes, change the issue subject, please.

@justinbmeyer justinbmeyer added the Bug label Aug 26, 2014

@justinbmeyer justinbmeyer added this to the 2.1.4 milestone Aug 26, 2014

@daffl daffl modified the milestones: 2.2.0, 2.1.4 Nov 3, 2014

@cklanac

This comment has been minimized.

Show comment
Hide comment
@cklanac

cklanac Feb 13, 2015

Contributor

Fixed in previous release. If you check the original fiddle http://jsfiddle.net/VVQ8k/1/ and open console, you'll see that the child nodes have an element attribute set to "li" element

Contributor

cklanac commented Feb 13, 2015

Fixed in previous release. If you check the original fiddle http://jsfiddle.net/VVQ8k/1/ and open console, you'll see that the child nodes have an element attribute set to "li" element

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