from underscore template to mustache.js

javascript, mustache, underscore.js

Solution

In your view you could make something like this:

Mustache.render(yourTemplate, {
     remaining: items.length > 1 ? true : false
}

Problem

I would like to change from `underscore template` to `mustache.js`. Since in mustache.js there are no `if statements` how can I change this piece of code in order to use `mustache.js` ? ``` <% if (done) { %> <span class="todo-clear"> <a href="#"> Clear <span class="number-done"><%= done %></span> completed <span class="word-done"><%= done === 1 ? 'item' : 'items' %></span> </a> </span> <% } %> ``` My solution is: ``` {{#total}} <span class="todo-count">{{ total }} <span class="number">{{ remaining }}</span> <span class="word"><%= remaining == 1 ? 'item' : 'items' %></span> left.--> </span> <span class="hint"> Drag tasks from one list into another and vice versa. </span> {{/total}} ``` It works for total variable, because it could be 0 or more, but I have no idea what is the best way to fix it on remaining variable, which could be 1 or more. ``` <span class="word"><%= remaining == 1 ? 'item' : 'items' %></span> left.</span> ``` It should be something like that: ``` <span class="word"> {{#remaining}} 'items' {{/remaining}} {{^remaining}} 'item' {{/remaining}} </span> ``` It does not work because remaining could be 1 or more.

Original source