include.html 641 B

1234567891011121314151617181920212223242526272829303132
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>include-demo</title>
  6. <script src="../dist/template.js"></script>
  7. </head>
  8. <body>
  9. <div id="content"></div>
  10. <script id="test" type="text/html">
  11. <h1>{{title}}</h1>
  12. {{include 'list'}}
  13. </script>
  14. <script id="list" type="text/html">
  15. <ul>
  16. {{each list as value i}}
  17. <li>索引 {{i + 1}} :{{value}}</li>
  18. {{/each}}
  19. </ul>
  20. </script>
  21. <script>
  22. var data = {
  23. title: '嵌入子模板',
  24. list: ['文艺', '博客', '摄影', '电影', '民谣', '旅行', '吉他']
  25. };
  26. var html = template('test', data);
  27. document.getElementById('content').innerHTML = html;
  28. </script>
  29. </body>
  30. </html>