EJS - 如何显示未显示的变量/变量

时间:2017-02-20 13:43:04

标签: javascript html node.js ejs embedded-javascript

我只是给予破败。

Server.js:

// load the things we need
var express = require('express');
var app = express();

// set the view engine to ejs
app.set('view engine', 'ejs');

// use res.render to load up an ejs view file

// index page 
app.get('/', function(req, res) {
    var tagline = "Any code of your own that you haven't looked at for six or more months might as well have been written by someone else";

    res.render('pages/index', {
        tagline: tagline
    });
});

// about page 
app.get('/about', function(req, res) {
    res.render('pages/about');
});

app.listen(8080);
console.log('8080 is the magic port');

在index.ejs中,我需要显示的位是:

<div class="jumbotron">
  <h1>This is great</h1>
  <h2><%= tagline %></h2>
  <p>Welcome to templating using EJS</p>
</div>

然而,当我一起运行这些代码时,我得到了所有页面,与<%= tagline %>部分相同。这对我来说非常烦人,因为这意味着我目前无法使用EJS变量。有人可以帮忙吗?!

0 个答案:

没有答案