I have a simple mustache template setup that takes an object player and creates a list element. What’s the best way to perform a javascript method on a variable in mustache? Here’s some sample code:
var playerTemplate = '<li><span class="player-position">{{ position }}</span><span class="player-name">{{ first_name }} {{ last_name }}</span></li>';
var playerRow = Mustache.to_html(playerTemplate, player);
$('ul#players-list').append(playerRow);
what i’d like to do is something like:
{{ position.toUpperCase() }}
I’d rather not change the object itself, because i may want {{ position }} to not be upper case in other situations. Any tips on the cleanest smartest way to do this?
Thanks much.
Mustache is intentionally very simple (“Logic-less templates”) so there’s not a lot you can do. One option is to add a
positionUCproperty:and then in the template:
You can also add functions:
and then in the template:
Perhaps you could switch to Handlebars and add a helper to uppercase things.