Mustache – Check Boolean object property within object array

Issue

Actually I’m using mustache-express, and I know that I can use conditionals like: {{^isFalse}} and {{#isTrue}}, this stuff is working fine, but my problem is:

I send an object array to template and list their properties with {{prop1}}{{prop2}}

My object has a Boolean property that is only true for the first object, and I need to grab another property from this object and set as audio element source, which I couldn’t do, despite this snippet. Probably I’m missing something… But this is what I tried with no success:

Access the Boolean property directly (as he did):

{{#myBoolean}}
<audio hidden src="{{myPath}}"></audio>
{{/myBoolean}}

Access within the array call, as I’m doing with my list:

{{#myArray}}
{{#myBoolean}}
<audio hidden src="{{myPath}}"></audio>
{{/myBoolean}}
{{/myArray}}

Is there any way I can do this without having to create a separate object?

Solution

The answer was:

{{#myArray.0}}
<audio hidden src="{{myPath}}"></audio>
{{/myArray.0}}

Answered By – nanquim

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published