ahjesus让nodejs支持dotjs模板
2014-05-11 22:19
316 查看
经过几天的实验加搜索,终于知道一个中间件可以解决这个问题了
Since doT (and probably your template engine of choice, as well) is accessed through consolidate, consolidate is the only additional module I need to require at the top of
I want to continue serving some of my other pages statically, so I add my template configuration stuff below the existing
Those three new lines set doT (as exposed by consolidate) as the view engine, register files ending in
npm install consolidate
consolidate传送门 传送门2 使用说明传送门 快照:ahjesus
Since doT (and probably your template engine of choice, as well) is accessed through consolidate, consolidate is the only additional module I need to require at the top of
server.js:
var express = require( "express" ), app = express(), cons = require( "consolidate" );
I want to continue serving some of my other pages statically, so I add my template configuration stuff below the existing
app.useline in my code:
app.use( express.static( _dirname + "/public" ) ); app.engine( "dot", cons.dot ); app.set( "view engine", "dot" ); app.set( "views", _dirname + "/public/views" );
Those three new lines set doT (as exposed by consolidate) as the view engine, register files ending in
.dotas templates, and tell Express to look in
/public/tmplfor templates to use. So when Node sees
res.render( "detail", { ... } ), it knows to expand
"detail"to
/public/tmpl/detail.dotand render it as a doT template. Now I can restart my server, go to http://localhost:3000/product/102, and see my template rendered statically, without creating a separate server-side file.
相关文章推荐
- ahjesus js 快速求幂
- doT.js模板引擎
- doT.js 模板引擎的使用
- html模板引擎(doT.min.js)和分页插件
- ahjesus用forever管理nodejs服务
- WebStorm+NodeJs创建支持Html模板的项目
- nodejs express框架 app.js文件该html模板
- ahjesus 让我的MVC web API支持JsonP跨域
- ahjesus使用T4模板自动维护实体
- PHP相册模块,支持Flash及JS模板插件安装。
- Gson传递list(包括doT.js模板使用)
- doT.js——前端javascript模板引擎问题备忘录
- JS精准倒计时(支持自定义模板)
- javascript模板添加nodejs支持
- 关于nodejs express4.X框架不支持layout模板的问题解决
- 关于nodejs express4.X框架不支持layout模板的问题解决
- 利用grunt+browserify预编译js模板文件,支持commonJS加载
- doT.js 模板引擎的使用
- js 模板引擎 为什么选择 dot
- doT js模板入门 3