我正在尝试与Swig 模板一起学习MEAN 堆栈。我正在从头开始编码,因为我尝试了一个 MEAN 框架,但它生成了很多文件,这对我来说太多了。
目前我的 Swig 模板 index.html 不呈现 HTML。这是我得到的输出:
{% include 'header.html' %}
<br>Welcome to my test website
正如我所期待的那样
This is coming from Header
<br>Welcome to my test website
为什么不渲染?
以下是我的文件夹结构:
--config
-config.js
--node_modules
-* //modules installed via npm link
--public
-header.html
-index.html
-package.json
-routes.js
-server.js
下面是每个文件的内容
配置.js
var port = process.env.PORT || 8080;
module.exports = {
dburl: 'mongodb://localhost/test',
port: port,
templateEngine: 'swig'
}
header.html
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<p> This is coming from Header</p>
索引.html
{% include 'header.html' %}
<p>Welcome to my test website</p>
</body>
包.json
{
"name": "test",
"version": "0.0.1",
"author": "Rukmaj Chandavar",
"dependencies": {
"express": "*",
"mongoose": "*",
"angular": "*",
"swig": "*",
"consolidate": "*"
}
}
路由.js
module.exports = function(app){
app.get('*',function(req, res){
res.send('index.html');
});
}
服务器.js
var express = require("express");
var app = express();
var mongoose = require("mongoose");
var config = require('./config/config');
var swig = require('swig');
var cons = require('consolidate');
mongoose.connect(config.dburl);
app.use(express.static(__dirname + '/public'));
app.set('views', __dirname + '/public');
app.engine('html', cons.swig);
app.set('view engine', 'html');
require('./routes') (app);
app.listen(config.port);
console.log('MeriDawat running on port ' + config.port)
以下是已安装节点模块的版本号
angular@1.2.18
consolidate@0.10.0
express@4.4.3
mongoose@3.8.12
passport@0.2.0
swig@1.3.2
我将不胜感激任何帮助解决此问题以帮助我继续前进。提前致谢。