-
安装
npm install --save art-template npm install --save express-art-template
-
配置
app.engine('html',require('express-art-template'))
配置使用art-template模板引擎
第一个参数表示,当渲染以.html结尾的文件时,使用art-template模板引擎
express-art-template是专门用来在Express中把art-template整合到Express中,虽然外面这里不需要记载art-template但是也必须要安装,原因:express-art-template依赖于art-template
-
使用
res.render('html模板名',{ 模板数据})
Express为Response相应对象提供了一个方法render,该方法默认是不可以使用的,除非配置了模板引擎。
第一个参数不能写路径,默认会去项目中的views目录查找该模板文件,也即Express约定:开发人员把所有视图文件都放在views目录中
-
修改默认访问views目录
app.set('views',render函数的默认访问路径);
express中使用art-template
猜你喜欢
转载自blog.csdn.net/chen__cheng/article/details/114677297
今日推荐
周排行