简体   繁体   English

如何覆盖奏鸣曲管理员中的显示字段

[英]How to override Show field in sonata admin

I want show the list of multiple attributes Name => value in a table overriding single field of only for PortsAdmin in ShowMapper我想在表中显示多个属性名称 => 值的列表,以覆盖ShowMapper中仅用于PortsAdmin的单个字段

Ports Entity mapped with PortsAttributes Entity. Ports实体映射到PortsAttributes实体。

Relation of entity is OneToMany Ports with multiple attributes.实体的关系是具有多个属性的OneToMany端口。

Admin View (Edit Action)管理员视图(编辑操作)

编辑属性列表视图

Show Action显示动作

显示属性列表

I want change attribute view same as edit Action.我想要更改属性视图与编辑操作相同。

You can create a custom template for the PostAttributes :您可以为PostAttributes创建自定义模板:

Example:例子:

/* ShowMapper in admin */
$showMapper->add('attributes', null, array(
    'template' => 'YOUR_TEMPLATE.html.twig' // <-- This is the trick
));

In your template, you can extend the base show field ( SonataAdminBundle:CRUD:base_show_field.html.twig or @SonataAdmin/CRUD/base_show_field.html.twig for symfony > 4.0), and override the field block.在您的模板中,您可以扩展基本显示字段(对于 symfony > 4.0, SonataAdminBundle:CRUD:base_show_field.html.twig@SonataAdmin/CRUD/base_show_field.html.twig ),并覆盖field块。 The variable named value stores the data in twig.名为value的变量将数据存储在 twig 中。

Example:例子:

YOUR_TEMPLATE.html.twig YOUR_TEMPLATE.html.twig

{% extends 'SonataAdminBundle:CRUD:base_show_field.html.twig' %}
{# for sf > 4.0 #}
{#  {% extends '@SonataAdmin/CRUD/base_show_field.html.twig' %} #}

{% block field %}
    {% for val in value %}
        {{ val.name }} - {{ val.value }} {# I'm just guessing the object properties #}
        <br/>
    {% endfor %}
{% endblock %}

@SlimenTN you can try changing this line in template file: @SlimenTN 您可以尝试更改模板文件中的这一行:

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

with this:有了这个:

{% extends '@SonataAdmin/CRUD/base_show_field.html.twig' %}

The rest of code seems ok (I have the same in a SF4 project)其余代码似乎没问题(我在 SF4 项目中有相同的代码)

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

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