Use a variable in a Jade include

前端 未结 5 1981
暖寄归人
暖寄归人 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:20

    this also works:

    //controller
    var jade = require('jade');
    res.render('show', {templateRender: jade.renderFile});
    
    
    //template
    != templateRender('my/path/'+dynamic+'.jade', options)
    

    This probably will not increase the performance that you would expect from using the 'view cache' setting (it's on by default in NODE_ENV === 'production'). Or even break the app (e.g. if files are not available on the hard drive while deploying new code). Also trying to use this trick in a client-side or isomorphic app will not work because the template can not be compiled.

提交回复
热议问题