This article brings you an example (code) of using template engine in js. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
<!DOCTYPE HTML> <html> <head> <meta charset="UTF-8"> <title>basic-demo</title> <script src="template-web.js"></script> </head> <body> <p id="content"></p> <script id="test" type="text/html"> {{if isAdmin}} <h1>{{title}}</h1> <ul> {{each list as value i}} <li>索引 {{i + 1}} :{{value}}</li> {{/each}} </ul> {{/if}} </script> <script> var data = { title: '基本例子', isAdmin: true, list: ['文艺', '博客', '摄影', '电影', '民谣', '旅行', '吉他'] }; var html = template('test', data); document.getElementById('content').innerHTML = html; </script> </body> </html>
Related recommendations:
Use js attributes to achieve the effect of horizontal drop-down menu in html5 (code)
multiparty implementation file in nodejs Uploaded code example
The above is the detailed content of An example of using template engine in js (code). For more information, please follow other related articles on the PHP Chinese website!