Posted By

mattneary on 12/29/10


Tagged

template mustache


Versions (?)

Mustache Sample Template


 / Published in: JavaScript
 

  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  

You need to login to post a comment.