简体   繁体   English

如何在IRIS中禁用自动转义

[英]How to disable AutoEscaping in IRIS

I insert HTML tags into database table: 我将HTML标记插入数据库表:

<table>
<tr>
   <td>1</td>
   <td>2</td>
   <td>3</td>
</tr>
</table>

And send retrieved data into View 并将检索到的数据发送到View

func MyEvent(ctx iris.Context){
        rows := ...
        ctx.ViewData("rows", rows[0])
        ctx.View("template.html")
}

How could I disable auto escaping just in this event? 如何仅在这种情况下禁用自动转义?

How you would get raw HTML through the template and into the output would depend on which template engine you're using with Iris. 如何通过模板获取原始HTML并进入输出,将取决于您与Iris一起使用的模板引擎。 Iris supports five template engines out-of-the-box : Iris支持五个现成的模板引擎

If you're using the standard html/template package then you'd mark the string as "safe HTML" using the template.HTML type: 如果您使用的是标准html/template包,则可以使用template.HTML类型将字符串标记为“安全HTML”。

ctx.ViewData("rows", template.HTML(rows[0]))

or add your own filter which just does a return template.HTML(s) and use that inside the template. 或添加您自己的过滤器,该过滤器仅会return template.HTML(s) 。HTML会在模板中使用该过滤器。

If you were using Handlebars then you'd use {{{...}}} in the template or raymond.SafeString in a helper : 如果您使用的是把手,则可以在模板中使用{{{...}}}或在助手中使用raymond.SafeString

{{{yourHTML}}}

If you're using one of the other template engines then you'd use whatever mechanism they offer for getting raw HTML through the template. 如果您使用其他模板引擎之一,则可以使用它们提供的任何机制来通过模板获取原始HTML。

All of this assumes, of course, that you're scrubbing and sanitizing the HTML before it gets into the database or before it gets from the database to the template. 当然,所有这些假设都是在HTML进入数据库之前或从数据库到达模板之前对HTML进行清理和清理的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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