首页 > 解决方案 > 编码在样式应答器中不起作用

问题描述

我正在使用 symfony,在我的控制器中我有类似的东西:

 $colors =" test > test2{
         color : #fff
         }";
 return $this->render(
        'Default/views/page.html.twig',
        array("colors" =>$colors)
       );

在我的树枝上,我有:

 <style>
      {{ colors }}
 </style>

但问题不是>我有&gt;,所以我的风格不适用。但如果我{{ colors }}在我之外做,script我有正确的>

标签: csstwig

解决方案


colorsvar 出于安全原因被转义,{{ colors|raw }}如果您确定自己在做什么,则必须使用。

https://twig.symfony.com/doc/2.x/filters/raw.html


推荐阅读