【发布时间】:2014-12-20 08:31:13
【问题描述】:
我有一个 html 文件 footer.html 存储网站的页脚,我想在不同的页面上重复使用它。如何使用 lodash/underscore 将其包含在模板文件 template.html 中?我已经阅读了这篇关于node-partial 的article,但我不确定node-partial 模块如何与Express 4 中的render 一起使用。
var express = require('express')
, app = express()
, http = require('http').createServer(app)
, _ = require('lodash')._
,cons = require('consolidate');
app.engine('html', cons.lodash);
app.set('view engine', 'html')
app.set('views', './views')
app.get('/', function(req, res){
res.render('index.html', {hello: 'Welcome !'})
});
Template file
<h1><%= hello %></h1>
<p><%= _('hello') %></p>
<% include './footer.html' %> // Can I add a footer file to the template?
【问题讨论】:
标签: javascript node.js express underscore.js lodash