Mustache Sample Template


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <script type="text/javascript" src="https://github.com/janl/mustache.js/raw/master/mustache.js"></script>
  2. <script type="text/javascript">
  3. data = {
  4. name : "Text",
  5. array : ["Item1","Item2","Item3"],
  6. myFunction: function () {
  7. return function(text, render){
  8. text = render(text);
  9. replacementText = "New Text";
  10. return replacementText;
  11. }
  12. }
  13. };
  14.  
  15. var template = "<h1>{{name}} vs. {{#myFunction}}{{name}}{{/myFunction}}</h1><ul>{{#array}}<li>{{.}}</li>{{/array}}</ul>";
  16.  
  17. html = Mustache.to_html(template, data);
  18.  
  19. document.write(html);
  20. </script>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.