jehugaleahsa / mustache-sharp

An extension of the mustache text template engine for .NET.
The Unlicense
306 stars 78 forks source link

Parent scope references #38

Open fuxo opened 9 years ago

fuxo commented 9 years ago

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}}.

oscaruribe commented 8 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.

jehugaleahsa commented 8 years ago

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}}.

oscaruribe commented 8 years ago

Yes but I can't use expressions like:

if @index % 2 == 0

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.

fuxo commented 8 years ago

@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.

oscaruribe commented 8 years ago

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.