JS Mustache IF/Else


This how you set if/else in JS Mustache

test_template.mustache
//If the lists is not empty

{{#lists}}

//not empty

{{/lists}}

//Else if lists is empty

{{^lists}}

//empty

{{/lists}}
 $.get('test_template.mustache', function(template) {
    var rendered = Mustache.render(template, {lists: data});
    $('#target').html(rendered);
  });

More documentation here about JS Mustache https://github.com/janl/mustache.js/

Published by

Emisyl

Is a web developer and a Php enthusiasts base in the Philippines

Other sites
https://planetcodes.blogspot.com

Leave a Reply

Your email address will not be published. Required fields are marked *

Emisyl