I have 2 entities with one to many relationship project and prototype And I\'ve been looking for a way to list the prototypes that belong to a project in the show action . here
One way is to define the template for your prototypes
field in showMapper
protected function configureShowFields(ShowMapper $showMapper)
{
$showMapper ->add('prototypes',null, array('template' => 'NamespaceYourBundle::Admin/prototypes.html.twig'));
}
Create Admin
folder in your bundle's resources folder and create prototypes.html.twig
file ,extend your twig template with sonata's base_show_field.html.twig
template and in {% block field %}
define your own markup looping through all related prototypes
{% extends 'SonataAdminBundle:CRUD:base_show_field.html.twig' %}
{% block field %}
{% spaceless %}
{% if object.getPrototypes() is not empty %}
Nom
Description
...
...
...
{% for prototype in object.getPrototypes() %}
{{ prototype.getNom() }}
{{ prototype.getDescription() }}
...
...
...
{% endfor %}
{% endif %}
{% endspaceless %}
{% endblock %}