Not sure if this counts as a bug, and seems to be by design as per the wording of the docs, and (at least) the perl and JS implementations, but a gotcha...
We make extensive use of {{#items.0}} type checks to see if an array has any items before rendering the container and the items themselves ({{#items}}{{value1}}{{value2}}{{/items}}).
This gives example code like:
The issue here is that the 0th item is now part of the context stack, meaning that if items 1+ do not have a specific named value, but the 0th does, that value will be rendered instead.
If you put the above mustache into the demo, you get this broken output:
It now thinks every item is "first" as it pulls that value from the {{#items.0}} context.
We can work around it in some cases, by changing {{subitem.value}} (which also exists at .0) to {{#subitem}}{{value}}{{/subitem}}.
This works, as the .n entries will have a subitem which becomes the new context, and then looks for value which .0 (and .n) doesn't.
Not sure if this counts as a bug, and seems to be by design as per the wording of the docs, and (at least) the perl and JS implementations, but a gotcha...
We make extensive use of
{{#items.0}}
type checks to see if an array has any items before rendering the container and the items themselves ({{#items}}{{value1}}{{value2}}{{/items}}
). This gives example code like:The issue here is that the 0th item is now part of the context stack, meaning that if items 1+ do not have a specific named value, but the 0th does, that value will be rendered instead. If you put the above mustache into the demo, you get this broken output:
It now thinks every item is "first" as it pulls that value from the
{{#items.0}}
context.We can work around it in some cases, by changing
{{subitem.value}}
(which also exists at.0
) to{{#subitem}}{{value}}{{/subitem}}
. This works, as the.n
entries will have asubitem
which becomes the new context, and then looks forvalue
which.0
(and.n
) doesn't.