Call methods on mustache variable in a template

Viewed 8438

I have a mustache template and I would like to call some function on the mustache variables ({{name}} in this case). Specifically, I want to call toLowerCase() method on the name variable.

<tbody>
  <script id="mytemplate" type="text/template">
    {{#cat}}
      <tr data-index="{{age}}-{{name}}"></tr>
    {{/cat}}
  </script>
</tbody>

I tried looking in the mustache docs but I couldn't find out how to do this. I tried doing

  1. <tr data-index="{{age}}-{{name.toLowerCase()}}"></tr>
  2. <tr data-index="{{age}}-{{name}}.toLowerCase()"></tr>

But I'm not getting what I expect. I render the template with this code which gets triggered on document ready.

$(function() {
      $.getJSON('/cats.json', function(data){
        var template = $("#mytemplate").html();
        var view     = Mustache.to_html(template, data);
        $("tbody").html(view);
      });
  })
1 Answers
Related