Is there any way to access this
within a conditional?
To explain a bit more… I have a loop over some items. I want to conditionally show the price if another value is set to something.
{
"firstName": "Terry",
"showPrice": "yes",
"items": [
{ "itemName": "Item 1", "itemPrice": "23.99" },
{ "itemName": "Item 2", "itemPrice": "50.99" }
]
}
{{#each items }}
<p>{{ this.itemName }}</p>
{{#equals @root.showPrice "yes"}}
<p>{{ this.itemPrice }}</p>
{{/equals}}
{{/each}}
The issue seems to be due to going back to the @root to check against the showPrice
value, it then breaks this
being accessible.
I've tried things like:
{{ this.itemPrice }} // doesn't work
{{ @root.this.itemPrice }} // doesn't work
{{ @root.items.this.itemPrice }} // doesn't work
{{ @root.items.[0].itemPrice }} // can now access, but only the 0 index
{{ @root.items.@index.itemPrice }} // doesn't work
Does anyone have any ideas?