mustache: support for backtrack path #163

Closed
whitecolor opened this Issue Nov 20, 2012 · 6 comments

Comments

Projects
None yet
4 participants
@whitecolor
Contributor

whitecolor commented Nov 20, 2012

It seems that can.js doesn't support backtrack paths

{{#person}}{{name}} - {{../company.name}}{{/person}}

https://github.com/wycats/handlebars.js#paths

do you plan to add it?

@moschel

This comment has been minimized.

Show comment
Hide comment
@moschel

moschel Dec 11, 2012

Contributor

we need this for loops too, so we can do...

{{#Grid.rows}}
  {{#Grid.cols}}
    <div>{{columnData ../. .}}</div>
  {{/Grid.cols}}
{{/Grid.rows}}
Contributor

moschel commented Dec 11, 2012

we need this for loops too, so we can do...

{{#Grid.rows}}
  {{#Grid.cols}}
    <div>{{columnData ../. .}}</div>
  {{/Grid.cols}}
{{/Grid.rows}}
@moschel

This comment has been minimized.

Show comment
Hide comment
@moschel

moschel Dec 11, 2012

Contributor

+1 for this. Without this support, here's what I have to do in a helper function to support a nested loop:

Mustache.registerHelper('columnData', function(cols){
    var res = [], col;
    for(var i=0; i<cols.length; i++){
        col = cols[i];
        res.push('<td><div class="yui-dt-liner">');
        res.push(this[col.name + 'Prepared'] ? this[col.name + 'Prepared'] : this[col.name])
        res.push('</div></td>');
    }

    return res.join("");
});
Contributor

moschel commented Dec 11, 2012

+1 for this. Without this support, here's what I have to do in a helper function to support a nested loop:

Mustache.registerHelper('columnData', function(cols){
    var res = [], col;
    for(var i=0; i<cols.length; i++){
        col = cols[i];
        res.push('<td><div class="yui-dt-liner">');
        res.push(this[col.name + 'Prepared'] ? this[col.name + 'Prepared'] : this[col.name])
        res.push('</div></td>');
    }

    return res.join("");
});
@amcdnl

This comment has been minimized.

Show comment
Hide comment
@amcdnl

amcdnl Dec 11, 2012

Contributor

@whitecolor In your case you should just be able to do company.name and it should work. Handlebars isn't a full implementation of Mustache so it doesn't support nesting contexts and context jumping like we do.

@moschel Brians case is valid though because if your in a nested loop like that you need the ability to hop up the stack to the parent context.

Contributor

amcdnl commented Dec 11, 2012

@whitecolor In your case you should just be able to do company.name and it should work. Handlebars isn't a full implementation of Mustache so it doesn't support nesting contexts and context jumping like we do.

@moschel Brians case is valid though because if your in a nested loop like that you need the ability to hop up the stack to the parent context.

@justinbmeyer

This comment has been minimized.

Show comment
Hide comment
@justinbmeyer

justinbmeyer Dec 11, 2012

Contributor

Do we have the ability to add things to the context via a helper?

We could have a name or var helper that takes 2 args. The first is the name of a property it will add to the current context, the second is the value.

It could be used like

{{var thing .}}

And then '.' could be referenced as thing in child contexts.

Sent from my iPhone

On Dec 11, 2012, at 2:24 PM, Austin notifications@github.com wrote:

@whitecolor In your case you should just be able to do company.name and it should work. Handlebars isn't a full implementation of Mustache so it doesn't support nesting contexts and context jumping like we do.

@moschel Brians case is valid though because if your in a nested loop like that you need the ability to hop up the stack to the parent context.


Reply to this email directly or view it on GitHub.

Contributor

justinbmeyer commented Dec 11, 2012

Do we have the ability to add things to the context via a helper?

We could have a name or var helper that takes 2 args. The first is the name of a property it will add to the current context, the second is the value.

It could be used like

{{var thing .}}

And then '.' could be referenced as thing in child contexts.

Sent from my iPhone

On Dec 11, 2012, at 2:24 PM, Austin notifications@github.com wrote:

@whitecolor In your case you should just be able to do company.name and it should work. Handlebars isn't a full implementation of Mustache so it doesn't support nesting contexts and context jumping like we do.

@moschel Brians case is valid though because if your in a nested loop like that you need the ability to hop up the stack to the parent context.


Reply to this email directly or view it on GitHub.

@justinbmeyer

This comment has been minimized.

Show comment
Hide comment
@justinbmeyer

justinbmeyer May 4, 2013

Contributor

+1.

Contributor

justinbmeyer commented May 4, 2013

+1.

@whitecolor

This comment has been minimized.

Show comment
Hide comment
@whitecolor

whitecolor Jan 7, 2014

Contributor

I think it should be put in docs, didn't see it there.

Contributor

whitecolor commented Jan 7, 2014

I think it should be put in docs, didn't see it there.

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