编写模板(采用script标签并带有属性id和type="text/html")
<div id="slowcity-film-content-div"></div>
<script id="slowcity-film-template" type="text/html">
{{if isAdmin}}
<h1>{{author}}</h1>
<ul>
{{each list as value i}}
<li>{{i+1}}:{{value}}</li>
{{/each}}
</ul>
{{/if}}
</script>
#渲染模板(film.js)
var data = {
author: '宫崎骏',
isAdmin: true,
list: ['千与千寻', '哈尔的移动城堡', '幽灵公主', '风之谷', '龙猫']
};
var slowcity-film-html = template('slowcity-film-template', data);
document.getElementById('slowcity-film-content-div').innerHTML = slowcity-film-html;