I'm curious as to whether Mustache has a syntax feature that is the opposite of the "Inverted Selection" syntax {{^foo}}
.
Let's say we have the data:
{
people: [
{ name: "Alice" },
{ name: "Bob" },
{ name: "Mallory" }
]
}
And the template:
<h3>People</h3>
<ul>
{{#people}}
<li>{{name}</li>
{{/people}}
</ul>
If we wanted to add an item if there are no people, we just add something like:
{{^people}}<li>No people</li>{{/people}}
But in my case I don't want to show the <h3>
and <ul>
if there are no people.
A syntax like {{?people}}
(representing the opposite / boolean negation of {{^people}}
) would be perfect for this situation, but does one exist?
Another alternative would be to preprocess the data, adding a value
has_people = Boolean(people.length)
and using {{#has_people}}
, but this seems counter-intuitive and against the logic-less (and I use that term lightly) paradigm.