Node.js模板模式

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);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章