squirrellyjs / squirrelly

Semi-embedded JS template engine that supports helpers, filters, partials, and template inheritance. 4KB minzipped, written in TypeScript ⛺
https://squirrelly.js.org
MIT License
599 stars 82 forks source link

Conditionals inside loop with use of variable loop #110

Closed florent1933 closed 5 years ago

florent1933 commented 5 years ago

I am using squirrelly as a templating engine for nodeJS.

I didn't succeed to use conditionals with the variable from the loop.

{{each(options.pixels)}}

  {{if(this.platform === 'facebook')}}
    {{@this.value}}
  {{/if}}
{{/each}}

Is it possible?

nebrelbug commented 5 years ago

Hi @florent1933, thanks for the question!

You just need to change this.platform to @this.platform.

{{each(options.pixels)}}

  {{if(@this.platform === 'facebook')}}
    {{@this.value}}
  {{/if}}
{{/each}}

I'm glad to hear that you're using Squirrelly! Feel free to ask any more questions you might have :+1:

nebrelbug commented 5 years ago

Let me know if this solves your problem.

florent1933 commented 5 years ago

It's working like a charm. Thanks @nebrelbug 🥇

nebrelbug commented 5 years ago

@florent1933 great! If you have any more questions, don't hesitate to contact me 😃