ahjesus让nodejs支持dotjs模板
经过几天的实验加搜索,终于知道一个中间件可以解决这个问题了
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 ofserver.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.use line 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 .dot as templates, and tell Express to look in /public/tmpl for templates to use. So when Node sees res.render( "detail", { ... } ), it knows to expand"detail" to /public/tmpl/detail.dot and 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让nodejs支持dotjs模板的更多相关文章
- ASP.NET MVC扩展自定义视图引擎支持多模板&动态换肤skins机制
ASP.NET mvc的razor视图引擎是一个非常好的.NET MVC框架内置的视图引擎.一般情况我们使用.NET MVC框架为我们提供的这个Razor视图引擎就足够了.但是有时我们想在我们的项目支 ...
- ASP.NET MVC 扩展自定义视图引擎支持多模板&动态换肤skins机制
ASP.NET mvc的razor视图引擎是一个非常好的.NET MVC 框架内置的视图引擎.一般情况我们使用.NET MVC框架为我们提供的这个Razor视图引擎就足够了.但是有时我们想在我们的 ...
- 关于nodejs express4.X框架不支持layout模板的问题解决
网上有有种方法是安装express-partials模块,然后在 app.set(‘view engine’, ‘ejs’); 这句后面加上app.use(partials());但是,经过我的反复尝 ...
- 让nodeJS支持ES6的词法----babel的安装和使用
要使用Babel, 我们需要nodeJS的环境和npm, 主要安装了nodeJS, npm就默认安装了 , 现在安装nodeJS很简单了, 直接下载安装就好了: 安装es-checker 在使用Bab ...
- vuejs+nodejs支持服务端渲染的博客系统
感悟 历时两个多月,终于利用工作之余完成了这个项目的1.0版本,为什么要写这个项目?其实基于vuejs+nodejs构建的开源博客系统有很多,但是大多数不支持服务端渲染,也不支持动态标题,只是做到了前 ...
- 让nodejs 支持 es6 import
备注: 尽管nodejs 新版本已经支持es6 的好多特性了,但是还是有部分不支持,为了使用,实际上我们有一个 比较强大工具 bable,下面介绍几个比较简单的用法. 1. bable-cli ...
- 学习篇:NodeJS中的模板引擎:jade
NodeJS 模板引擎作用:生成页面 在node常用的模板引擎一般是 1.jade --破坏式的.侵入式.强依赖(对原有的html体系不友好,走自己的一套体系)2.ejs --温和的.非侵入式的.弱依 ...
- nodejs根据word模板生成文档(方法二)
[推荐该方法,模板比较简洁] 1,代码, 这里采用的模块为 docxtemplater 和 open-docxtemplater-image-module,均为开源(docxtemplater 有收费 ...
- xcode6如何支持空模板
Single View Application 改成空模板的歩揍(xcode6.0.1): 1.删除info.plist 中的Main Storyboard file base name 选项 2.将 ...
随机推荐
- CSS基础(三):选择器
常用选择器 元素选择器,即html标记如div,ul,li,p,h1~h6,table等. p { font-size:14px; } h1 { color:#F00; } 复合选择器, 由两个选择器 ...
- 【Xamarin报错】libpng warning : iCCP: Not recognizing known sRGB profile that has been edited
报错: Xamarin Android 编译时发生以下错误: libpng warning : iCCP: Not recognizing known sRGB profile that has be ...
- ArcGIS Runtime for Android 使用异步GP服务绘制等值线
关于基于Android上ArcGIS Server GP服务的调用,已经有前辈给出了很好的例子: http://blog.csdn.net/esrichinacd/article/details/92 ...
- Android ListView OnItemLongClick和OnItemClick事件内部细节分享以及几个比较特别的属性
本文转自 http://blog.sina.com.cn/s/blog_783ede030101bnm4.html 作者kiven 辞职3,4个月在家休息,本以为楼主要程序员逆袭,结果失败告终继续码农 ...
- winedt设置自动显示行号[latex]
options--preferences--appearance 在show line numbers for modes下面的文本框里添加;Tex 这样新建或者打开tex文件的时候就自动显示行号了( ...
- Maxdos 9.3不能引导系统进入Maxdos
一.故障描述 最近安装一台新电脑安装的系统版本是windows7_professional_with_sp1_x64,安装完成后想用Maxdos对系统进行备份.出现错误:Warning: the hi ...
- tcp/ip协议listen函数中backlog参数的含义与php-fpm的502 Bad Gateway
To understand the backlog argument, we must realize that for a given listening socket, the kernel ma ...
- Log4net对文件的支持
RollingFileAppender循环记录日志(指定文件最大长度) <appender name="RollingFileAppender" type="log ...
- Til the Cows Come Home(最短路)
Til the Cows Come Home Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I ...
- [原]运行编译好的Android模拟器
Android源码编译好了之后,我们就可以运行它了. 1.配置环境变量: /data/data/Android$ export PATH=$PATH:$(pwd)/out/host/linux-x86 ...