简体   繁体   English

Twig原始过滤器 - 文档令人困惑

[英]Twig raw filter - documentation confusing

I've attached a snapshot of the Twig documentation for the raw filter, found here 我附上了原始过滤器的Twig文档的快照,可在此处找到

I cannot grok what it means. 我无法理解这意味着什么。 Can someone please elucidate? 有人可以澄清一下吗? Thankie... Thankie ...

树枝原料

From the same documentation: 从相同的文档:

The raw filter marks the value as being "safe" raw过滤器将值标记为“安全”

Raw is a filter, thus it does not render any output: it just trasforms it. Raw是一个过滤器,因此它不会呈现任何输出:它只是对它进行转换。 In this case, the "trasformation" consists in setting a "safe" mark on it so that the actual rendering (performed by the {{...}} tags) will not escape it. 在这种情况下,“trasformation”包括在其上设置“安全”标记,以便实际呈现(由{{...}}标签执行)不会逃脱它。

If you re-read the following examples at the light of this, they should be more clear. 如果您根据这一点重新阅读以下示例,它们应该更加清晰。

Let's take the second example: 我们来看第二个例子:

{{ false ? hola : hello|raw }}

This means: since we cannot know in advance if the condition will be true or false, and since one of the two possibile outcomes is not safe, the whole {{...}} will escape the output regardless of the "raw" filter. 这意味着:因为我们事先无法知道条件是真还是假,并且由于两个可能结果中的一个不安全,整个{{...}} 逃脱输出而不管“原始”过滤器。

They are warning you precisely about this kind of "unexpected" behaviour. 他们正在警告你这种“意外”的行为。 In such a case you should mark all as "raw": 在这种情况下,您应将所有标记为“原始”:

{{ (false ? hola : hello)|raw }}

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

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