-
安装
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
最新推荐文章于 2022-04-05 18:56:31 发布
本文介绍如何在Express框架中安装并配置art-template模板引擎,包括必要的npm包安装步骤及Express配置方法,并演示如何使用render方法来渲染.html模板。
922

被折叠的 条评论
为什么被折叠?



