SonataAdminBundle 自定义呈现列表中的文本字段 [英] SonataAdminBundle custom rendering of text fields in list

查看:34
本文介绍了SonataAdminBundle 自定义呈现列表中的文本字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 symfony2 和 SonataAdminBundle.我有一个名为 Post 的简单实体,其中我的内容字段基本上是 html 文本(来自 ckeditor 的记录).我需要在 Post 列表中将 content 字段显示为原始 html,而不对其进行转义.像这样破解 base_list_field 模板

I'm using symfony2 and SonataAdminBundle. I have a simple Entity called Post in which I have content field that is basically html text (from a ckeditor for the record). I need to display in the Post list the content field as raw html, without escaping it. Hacking base_list_field template like this

{% block field %}{{ value|raw }}{% endblock %}

有效,但这显然不是正确的方法.有什么提示吗?

works, but it's clearly not the proper way. Any hints?

解决了!我已经在 config.yml 中为 Sonata_doctrine_orm_admin 定义了一个自定义的 html 类型:

edit: SOLVED! I've defined a custom html type in the config.yml for sonata_doctrine_orm_admin:

sonata_doctrine_orm_admin:
    templates:
      types:
        list:
          html: MyBundle:Default:list_html.html.twig

并创建了我不转义 HTML 的自定义 list_html.html.twig 模板:

And created the custom list_html.html.twig template in which i do not escape HTML:

{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}

{% block field%}
    {{value|raw}}
{% endblock %}

现在在 PostAdmin 中,我可以在 configureListFields 方法中定义字段的行为:

Now in the PostAdmin I can define the behaviour of the field in the configureListFields method:

$listMapper
    ->add('content', 'html')

推荐答案

解决方案:

我已经在 config.yml 中为 Sonata_doctrine_orm_admin 定义了一个自定义的 html 类型:

I've defined a custom html type in the config.yml for sonata_doctrine_orm_admin:

sonata_doctrine_orm_admin:
    templates:
      types:
        list:
          html: MyBundle:Default:list_html.html.twig

并创建了我不转义 HTML 的自定义 list_html.html.twig 模板:

And created the custom list_html.html.twig template in which i do not escape HTML:

{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}

{% block field%}
    {{value|raw}}
{% endblock %}

现在在 PostAdmin 中,我可以在 configureListFields 方法中定义字段的行为:

Now in the PostAdmin I can define the behaviour of the field in the configureListFields method:

$listMapper
    ->add('content', 'html')

这篇关于SonataAdminBundle 自定义呈现列表中的文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆