art-template可在瀏覽器中,也可在node中使用
//在node使用art -template
//install npm install art-template默認下載到node_modules目錄,不要修改,也不支持修改
- 加載 art-template , install 的名字是什麼,require就是什麼
- 查找API,使用模板引擎,注意瀏覽器中用的是
- ** template(‘script 的 id’,{鍵值對對象}) **
var template = require('art-template')
var tplStr = `<!DOCTYPE html>
<html>
<head>
<title>{{ title }}</title>
</head>
<body>
<p> hello, My name is : {{ name }} </p>
<p> hello, I am from : {{ province }} </p>
</body>
</html>
`
var ret = template.render(tplStr,{
title: 'template',
name: 'mark',
province: 'hunan'
})
//模板引擎支持的是render方法,後面支持的是字符串。
console.log(ret);