简体   繁体   English

如何在带有nunjucks和gulp-data的JSON数据中使用HTML内容?

[英]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, NunjucksMJML在静态网站构建过程中使用它

JSON JSON格式

{
 message:"Welcome to <span class='red'>world</span>"
}

.nunjucks file .nu​​njucks文件

{{ message }}

is giving this output in final HTML output 在最终的HTML输出中给出了此输出

Welcome to &lt;span class=&#39;red&#39;&gt;world&lt;/span&gt;

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: falseautoescaping: 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.

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