Sonata Admin override template form_admin_fields.html.twig

I want to fully customize the way expanded choice looks in the admin edit form. I have found a template that shows it:

vendor/sonata-project/admin-bundle/Resources/views/Form/form_admin_fields.html.twig

I also have found a list of templates you can override in SonataAdmin https://sonata-project.org/bundles/admin/master/doc/reference/templates.html Unfortunately, there is not form_admin_fields.html.twig in the list. So I'm wondering how can override that template or at least {% block choice_widget_expanded %} from that template.

Upvotes: 1

Views: 1889

Answers (1)

Pez
Pez

Reputation: 1299

I believe this has to be overridden on the level of the storage bundle.

For instance, if using Doctrine and SonataAdminDoctrineOrmBundle, it can easily be overridden in configuration like so:

sonata_doctrine_orm_admin:
    templates:
        form: ["My/Templates/form_admin_fields.html.twig"]

Be sure to extend the doctrine form_admin_fields.html.twig in your own form_admin_fields.html.twig (rather than the base sonata admin twig file), ie:

{% extends '@SonataDoctrineORMAdmin/Form/form_admin_fields.html.twig' %}

Upvotes: 2

Related Questions