Node.js-视图引擎【1】-Swig集成express的安装与配置
2016-06-17 10:49
696 查看
node.js视图引擎,选来选去发现Swig最符合我的胃口哈哈。
一、安装Swig视图引擎
二、在node.js代码中配置如下
三、index.html模板页
四、使用
浏览器输入/index显示:hello, world!
五:工作原理
Swig reads template files and translates them into cached javascript functions. When we later render a template we call the evaluated function, passing a context object as an argument.
为了提升性能模板默认是会缓存在内存中的,如果修改了模板要重启node.js实例,当然,也可以通过选项禁用缓存。
Swig API帮助文档:http://paularmstrong.github.io/swig/docs/api/
一、安装Swig视图引擎
npm install -g swig
二、在node.js代码中配置如下
var app = require('express')(); var swig = require('swig'); app.engein('html', swig.renderFile); app.set('view engine', 'html'); app.set('views', __dirname + '/views');
三、index.html模板页
<html> {{content}} </html>
四、使用
app.get('/index', function(req, res) { res.render('index.html', {content: 'hello, world!'}); });
浏览器输入/index显示:hello, world!
五:工作原理
Swig reads template files and translates them into cached javascript functions. When we later render a template we call the evaluated function, passing a context object as an argument.
为了提升性能模板默认是会缓存在内存中的,如果修改了模板要重启node.js实例,当然,也可以通过选项禁用缓存。
Swig API帮助文档:http://paularmstrong.github.io/swig/docs/api/
相关文章推荐
- node.js 使用事件机制
- node.js学习笔记(8)--multer模块文件上传
- 【leetcode】19. Remove Nth Node From End of List
- 2个项目的免费node.js 服务器
- inode索引节点和硬连接软连接(草稿)
- Nodejs 处理表单提交数据
- node.js Waterline
- ubuntu系统安装nvm node npm cordova
- Node.js 应用程序的 5 条性能建议
- Hadoop可以连上8088,连不上50070,并且jps命令后并没有出现Namenode
- Linode vps使用日志
- Count Complete Tree Nodes
- node 实现SSO
- node起步(安装,建立服务,事件式编程)-01
- 19. Remove Nth Node From End of List [easy] (Python)
- Hadoop-2.4.1源码分析--HDFS HeartBeat(心跳检测)之NameNode端处理数据块增量汇报
- Hadoop-2.4.1源码分析--HDFS HeartBeat(心跳检测)之DataNode端数据块增量汇报
- hadoop Data上jps不出现Datanode
- 1115. Counting Nodes in a BST (30)
- Xml中SelectSingleNode方法,xpath查找某节点用法