symfony2 twig whitelist html tags

后端 未结 5 2419
盖世英雄少女心
盖世英雄少女心 2021-02-20 08:23

I pass a variable to my twig template in Symfony2, this variable may contain
html tags, I have tried to create an extension (function), but the variabl

5条回答
  •  遥遥无期
    2021-02-20 08:50

    {{ var|striptags('
    ')|raw }}

    works fine, but I don't know how to pass an array to the strip_tags php function with this twig filter.

    both

    {{ var|striptags(['
    ', ''])|raw }}

    and

    {% set allow = ['
    ', ''] %} {{ var|striptags(allow)|raw }}

    throw an "Array to string conversion" exception during the rendering of a template.

    Be also carefull that strip_tags php function doesn't escape html attribute like "onclick".

提交回复
热议问题