Skip to content
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

mustache: support for backtrack path #163

Closed
wclr opened this issue Nov 20, 2012 · 6 comments
Closed

mustache: support for backtrack path #163

wclr opened this issue Nov 20, 2012 · 6 comments
Assignees
Milestone

Comments

@wclr
Copy link
Contributor

wclr 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
Copy link
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
Copy link
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
Copy link
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
Copy link
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.

@justinbmeyer
Copy link
Contributor

+1.

@wclr
Copy link
Contributor Author

wclr 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
Projects
None yet
Development

No branches or pull requests

4 participants