Open fuxo opened 9 years ago
fuxo would you mind sharing the for? I'm trying to do an {{#even}} {{#odd}} {{/even}} helper and need to access the index in the each loop.
Just an idea, but the #each tag exposes an #index tag within its scope. If you want to refer to it in an #if, you can say {{#if @index}}
.
Yes but I can't use expressions like:
Best regards
Oscar Uribe Founder / Chief Executive Officer oscar.uribe@ungapped.commailto:oscar.uribe@ungapped.com +46 733 526 000
[Ungapped]http://www.ungapped.com/ Ungapped www.ungapped.comhttp://www.ungapped.com/ R?dmansgatan 65 | 113 60 Stockholm Sweden Follow: Facebookhttps://www.facebook.com/ungapped | Twitterhttps://twitter.com/ungapped | LinkedInhttps://www.linkedin.com/company/ungapped | Pinteresthttps://www.pinterest.com/ungapped/
9 mars 2016 kl. 03:31 skrev Travis Parks notifications@github.com<mailto:notifications@github.com>:
Just an idea, but the #each tag exposes an #index tag within its scope. If you want to refer to it in an #if, you can say {{#if @index}}.
Reply to this email directly or view it on GitHubhttps://github.com/jehugaleahsa/mustache-sharp/issues/38#issuecomment-194251734.
@oscaruribe here you are...
https://gist.github.com/fuxo/4a85e908477d63855563c711f5cfdb61
Sorry, I have noticed this is c# related. I ended up with a javascript based implementation.
Yes, I'm using the mustache-sharp implementation. What I really want is to add #foreach with a limit (so it'll only run X loops even tho array is longer) and also the possibility to do math in the #if clause. I know it goes against "logicless" but still pretty nifty for creating some logic in the templates.
I created a "for" helper in order to be able to generate content using {{#for min max}} ... {{/for}} and use 'this' for index reference. I want to use nested for blocks, but can't reference parent block index neither with {{../this}}, nor {{this.this}}.