Reputation: 1060
I want to check in Mustache if a value (not a boolean) is equal to a string. I saw in a random tutorial that you can use a function to define the condition but I haven't seen any documention on the syntax for that. Does anyone know how to do it?
Upvotes: 0
Views: 9792
Reputation: 23062
The workaround is to simply create a wrapping condition variable that is evaluated outside of the mustache template, as you may already know.
var displaySection = false;
if(typeof input == 'string'){
displaySection=true;
}
And then wrap whatever you want to do in a section tag
{{#displaySection}}
Upvotes: 4
Reputation: 4918
As Theron said, Mustache is a logic-less templating library and cannot handle conditions (you should use javascript beforehand for that).
If you really want to handle conditional blocks in your templates you should check out http://handlebarsjs.com/.
Upvotes: 1