How to override the Show field in sonata admin

I want to show a list of several Name => value attributes in a table, overriding one field only for PortsAdmininShowMapper

PortsAn object displayed using PortsAttributesEntity.

Entity relationship OneToManyPorts with multiple attributes.

Administrator view (edit action)

Edit Attribute List View

Show action

Show attribute list

I want to change the attribute of the change attribute in the same way as the Action.

+4
source share
1 answer

You can create your own template for PostAttributes:

Example:

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

show show (SonataAdminBundle:CRUD:base_show_field.html.twig) field. value .

:

YOUR_TEMPLATE.html.twig

{% extends 'SonataAdminBundle: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 %}
+10

Source: https://habr.com/ru/post/1624049/


All Articles