How to override Show field in sonata admin
You can create a custom template for the 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
), and override the field
block. The variable named value
stores the data in twig.
Example:
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 %}