简体   繁体   English

动态视图编译和渲染express.js

[英]Dynamic view compilation and rendering express.js

Is there a way to compile and render a .jade view on the fly eg. 是否有一种方法可以即时编译和渲染.jade视图。 if it was stored in a db or would it have to be written to the file system first or is it possible to hook into the view system to achieve this. 如果它存储在数据库中,还是必须先将其写入文件系统,或者可以挂接到视图系统中以实现此目的。

What I know is that Express/Jade allow template modification without restarting the server. 我所知道的是Express / Jade允许模板修改而无需重新启动服务器。

Also, instead of trying to hook Express to render a string, why don't you simply use jade directly and send it to the client ? 此外,为什么不尝试挂钩Express来呈现字符串,为什么不直接使用jade并将其发送给客户端呢? Few untested, pourly ordered lines of code to help : 很少有未经测试的,有序的代码行可以帮助您:

var jade = require('jade');    

app.get('/', function(req, res){
    var fn = jade.compile('string of jade');
    res.send(fn(locals));
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM