There are two solutions to your problem.
Using selections and inverted selections
Here is an example from the mustache documentation:
{
"repos": []
}
Template:
{{#repos}}<b>{{name}}</b>{{/repos}}
{{^repos}}No repos :({{/repos}}
Conclusion:
No repos :(
As you can see, inverted selections allow me to do conditional logic. In your case, it will look something like this:
Json:
var viewModel = {
badges:[]
}
viewModel.anyBadges = badges.length >0;
Mustache:
<div class="badges-unlocked">
{{#anyBadges}}
<h2>Unlocked!</h2>
{{/anyBadges}}
{{#badges_unlocked}}
<a href="#" class="badge">
<strong>{{ name }}</strong>
</a>
{{/badges_unlocked}}
Do not follow logic without patterns
, . Mustache, , . Handlebars, - ( javascript).
, Mustache readme