1
votes

I'm trying to override single template of show action like this:

public function configureShowFields(ShowMapper $showMapper)
    {
        $showMapper
            ->add('smsShipments',null, array(
                'template' => 'sms_shipment_list.html.twig'
            ))    
    }

but I'm getting a warning like this:

An error occured trying to load the template "sms_shipment_list.html.twig" for the field "smsShipments", the default template "@SonataAdmin/CRUD/base_show_field.html.twig" was used instead.

And error consequently like this:

Uncaught PHP Exception Twig_Error_Runtime: "An exception has been thrown during the rendering of a template ("Warning: nl2br() expects parameter 1 to be string, object given")." at C:\xampp_7\htdocs\project_name\vendor\sonata-project\admin-bundle\src\Resources\views\CRUD\base_show_field.html.twig line 23

This works great in Symfony 3.1. Could you provide an alternative solution to override show element or show action for single admin?

1
So, please show us your templateJim Panse

1 Answers

1
votes

Pulling from this SonataAdminBundle guide on the official Symfony 4.x documentation, I see that you'll need to have your twig template in templates/Namespace/sms_shipment_list.html.twig.

Then, then refer to it in the options argument as @App/Namespace/sms_shipment_list.html.twig.

Something like this, then:

public function configureShowFields(ShowMapper $showMapper)
{
    $showMapper
        ->add('smsShipments',null, array(
            'template' => '@App/Namespace/sms_shipment_list.html.twig'
        ))    
}