Liquid-Node 是一种基于 promise 的模板语言,可用于在异步数据库调用(除其他外)之后创建模板。没有对 ExpressJS 的内置支持。
让 Express 使用 Liquid-Node 作为其 View 引擎的最佳方式是什么?
最佳答案
我想出的最好的方法是使用 Vow-fs 作为 fs Promise(在 Livescript 中),并假设使用扩展名“.liquid”调用 View :
vowfs = require \vow-fs
Liquid = require \liquid-node
app.engine \.liquid, (filename, options, fn) ->
vowfs.read filename
.then (res) ->
content = res.toString!
template = Liquid.Template.parse content
template.render options
.then (res) -> fn null, res
关于node.js - 让 Liquid-Node 和 Express 更好地发挥作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17900497/