Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nodejs中ejs作为模板引擎的时候如何使用片段视图遍历 #3

Open
milixie opened this issue Nov 3, 2016 · 0 comments
Open

Comments

@milixie
Copy link
Owner

milixie commented Nov 3, 2016

1.安装express-partials

npm install express-partials -g

2.在app.js中引入

var partials = require('express-partials');

var list = require('./routes/list');

var app = express();
app.set('view engine', 'ejs');
app.use(partials());

app.use('/list', list);

3.在list.js中

var express = require('express');
var router = express.Router();
router.get('/', function(req, res){
    res.render('list', {
        items: ['mili', 1994, 'girl']
    });
});

module.exports = router;

4.在list.ejs中:
<ul> <%- partial('listitem', items)%> </ul>

5.在listitem.ejs中:
<li><%= listitem %></li>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant