tmpl.html 767 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>tmpl-demo</title>
  6. <script src="../dist/template.js"></script>
  7. </head>
  8. <body>
  9. <h1>与tmpl兼容</h1>
  10. <script id="test" type="text/html">
  11. <% if (title) { %>
  12. <h3><%= title %></h3>
  13. <% } else { %>
  14. <h3>无标题</h3>
  15. <% } %>
  16. <ul>
  17. <% for (var i = 0; i < list.length; i ++) { %>
  18. <li>索引 <%= i + 1 %> :<%= list[i] %></li>
  19. <% } %>
  20. </ul>
  21. </script>
  22. <script>
  23. // 模拟tmpl的api
  24. var tmpl = template;
  25. template.helper('tmpl', template.render);
  26. template.isEscape = false;
  27. var html = '';
  28. var data = {
  29. title: '我的标签',
  30. list: ['文艺', '博客', '摄影', '电影', '民谣', '旅行', '吉他']
  31. };
  32. html = tmpl('test', data);
  33. document.write(html);
  34. </script>
  35. </body>
  36. </html>