最近我发现Jade是一个非常酷的模板。
但API对我来说似乎有点混乱。
在其官方页面(http://jade-lang.com/api/)上,它定义了options
对象,如下所示:
{
filename:string
pretty:boolean
self:boolean
debug:boolean
compileDebug:boolean
compiler:class
globals:array
}
但是当我搜索其他一些文档时,我发现我可以传入一个JSON对象作为向我的模板注入变量,这将取代像#{something_in_json.value}
JSON就像:
"something_in_json":"this is a value"}
我的问题是,如果我想使用这两种功能,该怎么办?我想传入JSON变量并使用参数(例如,我想使用pretty:true
)。
答案 0 :(得分:1)
有两种方法可以做到这一点
将您的JSON数据与Jade的选项合并
// assuming jQuery is available
$.extend(data, jade_options, json_data);
jade.render(jade_source, data);
使用Jade的编译功能,有点丑陋
var fn = jade.compile(jade_source, jade_options);
fn(data); // returns compiled jade template e.g. <html>...