gpt4 book ai didi

closures - 如何在Google Closure模板中传递html参数

转载 作者:行者123 更新时间:2023-12-02 04:27:14 26 4
gpt4 key购买 nike

伙计们,我想传递一个包含 Google Closure Template 中 html 字符的参数,但我得到的只是文字 html 文本。如何做到这一点?

到目前为止我尝试过的是:

{template .modal autoescape="strict" kind="html"}
{$html_content}
{/template}

我一直在阅读this但这不是很有帮助。谢谢

最佳答案

{template .modal}
{$html_content |noAutoescape}
{/template}

将打印您的 HTML。但请注意,不鼓励在模板中使用 |noAutoescape

Discouraged: It's easy to accidentally introduce XSS attacks when the assertion that content is safe is far away from where it is created. Instead, wrap content as sanitized content where it is created and easy to demonstrate safety.
Google Closure Templates Functions and Print Directives


或者,如果您确定 $html_content 是“安全”HTML,您可以在将参数传递给模板的位置指定它:

goog.require('soydata.VERY_UNSAFE');
goog.require('template.namespace');

var container = document.getElementById('modal');
var html = '<strong>HTML you trust!</strong>';

container.innerHTML = template.namespace.modal({
html_content: soydata.VERY_UNSAFE.ordainSanitizedHtml(html);
});

然后您的初始模板将按原样打印 HTML:

/**
* @param html_content HTML markup
*/
{template .modal autoescape="strict" kind="html"}
{$html_content}
{/template}

关于closures - 如何在Google Closure模板中传递html参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26039391/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com