Search code examples
symfonytemplatessonata-adminsymfony-sonata

Sonata Admin overrides layout template per one Admin


I try to override layout template in Sonata Admin. I did all steps founded in official documentation, but my changes don`t work.

I did:

  1. Copied from vendor appropriate template (standard_layout.html.twig) to app/Resources/SonataAdminBundle/views/. I will check if I override here template my changes applied to all of Admins in project (I want have this change only in one Admin)

  2. In next step I created new file in my Bundle (Name/InfoBundle/Resources/views/JobOffer) and add there my custom template: findCandidate.html.twig. Below is content of this file:

    https://gist.github.com/anonymous/5f4780a1ae8d7329cd91

  3. Added to bundle service:

    name_info.admin.offers:
    
        class: Name\InfoBundle\Admin\JobOfferAdmin
        tags:
            - {name: sonata.admin, manager_type: orm, group: Info, label: Job offers}
        arguments: [~, Name\Info\Entity\JobOffer, NameInfoBundle:JobOffer]
        calls:
            - [ setTemplate, [findCandidate, NameInfoBundle:JobOffer:findCandidate.html.twig]]
    

After that my changes are not applied. So probably I made mistake in services or maybe I have to call this template also in controller? I am not sure where I make mistake. Could anyone help me?


Solution

  • Probably you mistyped a template placeholder in setTemplate function.

    Try to set it like:

    calls:
        - [setTemplate, [layout, NameInfoBundle:JobOffer:findCandidate.html.twig]]
    

    It will change a standard_layout only for the selected admin.