本文介绍了Sonata Admin Bundle上的原始过滤器configureShowFields的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Symfony2和Sonata Admin Bundle进行项目.如何在动作configureShowFields中应用细枝的原始过滤器(以显示格式化的文本)?
I'm doing a project with Symfony2 and Sonata Admin Bundle.How I can apply the filter raw of twig (to display formated text) in action configureShowFields?
我不会覆盖Sonata模板...
I would not override Sonata templates...
我的configureShowFields的代码:
The code of my 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.
来自base_show_field.html.twig:
From the base_show_field.html.twig:
{% block field %}
{% if field_description.options.safe %}
{{ value|raw }}
{% else %}
{{ value|nl2br }}
{% endif %}
{% endblock %}
这篇关于Sonata Admin Bundle上的原始过滤器configureShowFields的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!