BorisMoore / jsrender

A lightweight, powerful and highly extensible templating engine. In the browser or on Node.js, with or without jQuery.
http://www.jsviews.com
MIT License
2.67k stars 339 forks source link

{{if}} tag doesn't work on keys with array or object with properties #365

Closed lolbat closed 3 years ago

lolbat commented 3 years ago

I have an object that I am rendering in JSRender. Almost everything works except for the evaluation of a nested object I have.

"traits": {
  "admin": true,
  "editor": true,
  "writer": true
}

It is part of a larger object that I am sending to the template.

I have been trying to get JSRender to display an icon next to a name based on the traits.

{{if traits.admin}}
  <div class="icon iconadmin"></div>
{{else traits.editor}}
  <div class="icon iconeditor"></div>
{{else traits.writer}}
  <div class='icon iconwriter'></div>
{{/if}}

I have tried using a series of distinct {{if}} tags as well but in each case the template only renders the first icon the user has in their traits object.

The template will render correctly if I use {{props}}

{{props traits}}
 {{if prop}}
    <div class="icon icon{{>key}}"></div>
  {{/if}}
{{/props}}
lolbat commented 3 years ago

There must have been some issue in the template or the CSS that was rendering it but I have retested and the issue is no longer a problem