简体   繁体   English

Sonata Admin Bundle上的原始过滤器configureShowFields

[英]Raw filter on Sonata Admin Bundle configureShowFields

I'm doing a project with Symfony2 and Sonata Admin Bundle. 我正在使用Symfony2和Sonata Admin Bundle进行项目。 How I can apply the filter raw of twig (to display formated text) in action configureShowFields? 如何在动作configureShowFields中应用细枝的原始过滤器(以显示格式化的文本)?

I would not override Sonata templates... 我不会覆盖Sonata模板...

The code of my configureShowFields: 我的configureShowFields的代码:

protected function configureShowFields(ShowMapper $showMapper)
    {
        $showMapper
            ->add('active')
            ->add('title')
            ->add('subtitle') // I need this field with twig RAW filter
            ->add('description') //I need this field with twig RAW filter
            ->add('url')
            ->add('date')
            ->add('tags')
            ->add('file');
    }

You can use the "safe" sonata field option as follow: 您可以使用“安全”奏鸣曲字段选项,如下所示:

protected function configureShowFields(ShowMapper $showMapper)
{
    $showMapper
        ->add('subtitle', null, array('safe' => true))
    ;
}

It will add the "raw" twig filter to your entity field. 它将“原始”树枝过滤器添加到您的实体字段。

From the base_show_field.html.twig: 在base_show_field.html.twig中:

{% block field %}
    {% if field_description.options.safe %}
       {{ value|raw }}
    {% else %}
       {{ value|nl2br }}
    {% endif %}
{% endblock %}

You need to make a custom template. 您需要制作一个自定义模板。

Under: 下:

sonata_doctrine_orm_admin:
  templates:
    types:
      list:
        array:      SonataAdminBundle:CRUD:list_array.html.twig
        *** other existing declarations ***
        raw:        MyBundle:CRUD:raw.html.twig

Then make the template that the declaration maps to, and give 'raw' as the second argument to add field. 然后,创建声明映射到的模板,并将“ raw”作为添加字段的第二个参数。 It'll then call your new template to render that field. 然后它将调用您的新模板来渲染该字段。

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

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