css - 编码在样式应答器中不起作用

标签 css twig

我正在使用 symfony,在我的 Controller 中我有类似的东西:

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

在我的 Twig 上我有:

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

但问题不是 > 我有 > 所以我的风格不适用。 但是如果我在 script 之外执行 {{ colors }} 我有正确的 >

最佳答案

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

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

关于css - 编码在样式应答器中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50599718/

相关文章:

css - 图标字体 - icomoon - @font-face 在不同的服务器上不显示

html - 使用主页面滚动在固定 DIV 上滚动

forms - 有没有办法在 symfony2 中围绕输入包装标签?

php - 使用 Javascript 访问通过 Twig 传递的变量

variables - 如何在 Twig 过滤器中使用变量 'replace'

html - 带有负定位的 <hr> 上的 IE10 伪元素不起作用

html - href 区域太大,大,试过 inline-block

Javascript 根据浏览器大小将 CSS 左值从 px 更改为 %

forms - Symfony2 choice_widget 只打印没有标记的标签?

php - Silex v1.3 到 Silex v2 : Twig_Error_Runtime