Use a variable in a Jade include

前端 未结 5 1977
暖寄归人
暖寄归人 2020-11-27 14:22

I\'m working with Jade and Express and I would like to use a variable in my include statement. For example:

app.js

app.get(\'/admin\', function (req,         


        
5条回答
  •  一整个雨季
    2020-11-27 15:00

    AFAIK JADE does not support dynamic including. What I suggest is to "include" outside the template, i.e.

    app.js

    app.get('/admin', function (req, res) {
        var Admin = require('./routes/admin/app').Admin;
        var page = 'admin';
    
        var templates = page + '/templates/';
    
        // render template and store the result in html variable
        res.render(templates, function(err, html) {
    
            res.render(Admin.view, {
                title: 'Admin',
                page: page,
                html: html
            });
    
        });
    
    });
    

    layout.jade

    |!{ html }
    

提交回复
热议问题