能否使用Pug模板将HTML页面渲染为字符串呢?在Node.js中,您可以像这样使用“Pug模板”生成HTML页面:
var express = require('express')
var app = express()
app.set('view engine', 'pug')
var mytemplate="html\n\thead\n\tbody";
app.get('/', function (req, res) {
res.render(
'index',
{ title: 'Hey Hey Hey!', message: 'Yo Yo'})
})
app.listen(3000, function () {
console.log('Example app listening on port 3000!')
})
模板文件应该放在./views/index.pug。
可以使用保存在“mytemplate” -变量中的模板,而不是文件内容吗?
const
防止变量重新赋值,这种方式更加严格,我认为对于模块引用更好 :) - robertklep