SonataAdminBundle自定义渲染列表中的文本字段
问题描述:
我正在使用symfony2和SonataAdminBundle。 我有一个简单的实体称为邮政,其中我有内容字段,基本上是HTML文本(从记录ckeditor)。我需要在Post列表中将内容字段显示为原始HTML,而不会将其转义。 这样SonataAdminBundle自定义渲染列表中的文本字段
{% block field %}{{ value|raw }}{% endblock %}
作品黑客base_list_field模板,但它显然不是正确的方式。 任何提示?
编辑:解决!我在config.yml定义的自定义HTML类型sonata_doctrine_orm_admin:
sonata_doctrine_orm_admin:
templates:
types:
list:
html: MyBundle:Default:list_html.html.twig
而创建的自定义模板list_html.html.twig在我不逃避HTML:
{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}
{% block field%}
{{value|raw}}
{% endblock %}
现在所述PostAdmin我可以在configureListFields方法定义字段的行为:
$listMapper
->add('content', 'html')
答
解决办法:
我在config.yml定义的自定义HTML类型sonata_doctrine_orm_admin:
sonata_doctrine_orm_admin:
templates:
types:
list:
html: MyBundle:Default:list_html.html.twig
而创建的自定义模板list_html.html.twig在我不逃避HTML:
{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}
{% block field%}
{{value|raw}}
{% endblock %}
现在,在PostAdmin我可以定义字段的行为在configureListFields方法:
$listMapper
->add('content', 'html')
你应该添加自己的答案,并接受它(小延迟之后,我认为它的总重量o天自我接受),而不是用解决方案编辑你的答案。 – Matt 2012-09-06 20:19:37