[英]How to use content with HTML inside JSON data with nunjucks and gulp-data?
how to use HTML with JSON with Gulp-data ? 如何在带有Gulp-data的 JSON中使用HTML? I'm using it in a static website building process with Gulp, Nunjucks and MJML
我正在用Gulp, Nunjucks和MJML在静态网站构建过程中使用它
JSON JSON格式
{
message:"Welcome to <span class='red'>world</span>"
}
.nunjucks file .nunjucks文件
{{ message }}
is giving this output in final HTML output 在最终的HTML输出中给出了此输出
Welcome to <span class='red'>world</span>
Looks like Nunjucks uses autoescaping: true
by default (due to their docs). 看起来Nunjucks使用自动
autoescaping: true
默认情况下为autoescaping: true
(由于其文档)。
gulp-nunjucks-render
uses envOptions
to configure template engine (line 20 of its code). gulp-nunjucks-render
使用envOptions
配置模板引擎(其代码的第20行)。
You can try to pass autoescaping: false
in options in gulp to disable escaping (more info in readme ). 您可以尝试传递自动
autoescaping: false
在autoescaping: false
中的选项中为autoescaping: false
以禁用转义( 自述文件中的更多信息)。
Or you can just use {{ message | safe }}
或者,您可以只使用
{{ message | safe }}
{{ message | safe }}
in your template to disable escaping for one piece of code. {{ message | safe }}
,以禁止对一段代码进行转义。 Mode info in API Docs: Autoescaping API文档中的模式信息:自动转义
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.