从Hogan-express模块​​获取HTML中的变量值

时间:2016-02-05 21:52:26

标签: node.js express

js和express.js,我试图从Express-hogan模板中获取我的HTML中的标题值但是我没有在我的HTML元素上获得所需的输出,我在节点中运行了app.js并且(正在运行在浏览器上的localhost-port:3000),这是express(app.js)的代码:

var express = require('express'),
    app = express(),
    path = require('path');

app.set('views', path.join(__dirname, 'views'));

app.engine('html', require('hogan-express'));
app.set('view engine', 'html');
app.use(express.static(path.join(__dirname, 'public')));

app.route('/').get(function(req, res, next) {
    res.render('index', {
        title: 'Welcome to chatKat'
    });

})
app.listen(3000, function() {

    console.log('chatKat running on por t 3000');

以下是我的html视图:

<!DOCTYPE html>
<html>
   <head>
      <meta charset="utf-8">
      <title>{{title}}</title>
   </head>
   <body>
      <div class="hm-container">
         <h1 class="hm-title">My face book login</h1>
         <a href="#"><img src="images/facebook26.png"></a>  
         </h1>
      </div>
   </body>
</html>

和package.json:

{
"name": "chatkat",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"express": "^4.13.4",
"hogan-express": "^0.5.2",
"passport": "^0.2.0",
"passport-facebook": "^1.0.3",
"qr-image": "^3.1.0",
"socket.io": "^1.4.4"
},
"devDependencies": {
"express": "~4.2.0",
"hogan-express": "~0.5.2"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}

0 个答案:

没有答案