Newline 如何使用Sonata管理包列表视图轻松显示换行符
我应该如何向SonataAdminBundle中的列表视图表添加换行符 我向实体添加了一个函数,如下所示:Newline 如何使用Sonata管理包列表视图轻松显示换行符,newline,symfony-2.1,sonata-admin,Newline,Symfony 2.1,Sonata Admin,我应该如何向SonataAdminBundle中的列表视图表添加换行符 我向实体添加了一个函数,如下所示: getTest() { return "test 1 \n test 2"; } 在我的configureListFields函数中,我以如下方式添加字段: $listMapper->add('test', null, array('label' => 'Test')) 我还尝试将类型更改为文本、字符串和条令文本,但没有效果 使用而不是\n没有帮助,因为输出被转换为
getTest() {
return "test 1 \n test 2";
}
在我的configureListFields
函数中,我以如下方式添加字段:
$listMapper->add('test', null, array('label' => 'Test'))
我还尝试将类型更改为文本
、字符串
和条令文本
,但没有效果
使用
而不是\n
没有帮助,因为输出被转换为html实体。我发现了一种可能性:覆盖文本模板的基本列表字段.html.twig模板:在定义块字段时添加nl2br
过滤器:
list\u text\u field.html.twig
<td class="sonata-ba-list-field sonata-ba-list-field-{{ field_description.type }}" objectId="{{ admin.id(object) }}">
{% if
field_description.options.identifier is defined
and field_description.options.route is defined
and admin.isGranted(field_description.options.route.name == 'show' ? 'VIEW' : field_description.options.route.name|upper, object)
and admin.hasRoute(field_description.options.route.name)
%}
<a href="{{ admin.generateObjectUrl(field_description.options.route.name, object, field_description.options.route.parameters) }}">
{%- block field %}{{ value|nl2br }}{% endblock -%}
</a>
{% else %}
{{ block('field') }}
{% endif %}
</td>
configureListFields
$listMapper->add('test', 'text', array('label' => 'Test'))
有一个更简单的方法:
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->add('message', null, array(
'template' => 'SensioPlatformBundle:Admin:AuditTrail/message.html.twig',
))
//...
然后在模板中:
<td>
{{ value|nl2br }}
</td>
{{value}nl2br}
<td>
{{ value|nl2br }}
</td>