Extend "standard_layout.html.twig" template from bundle doesn't work

2,069 views
Skip to first unread message

reyn...@gmail.com

unread,
Nov 27, 2013, 1:43:39 PM11/27/13
to sonata...@googlegroups.com
Hi there, I'm trying to extends the default SonataAdminBundle template to get the same behavior in my Bundle at view level but I can't since menus and every else dissapears. This is what I do:

{% extends 'SonataAdminBundle::standard_layout.html.twig' %}
{% block sonata_page_content %}
    something
{% endblock %}

Take a look at attached images, (1) is how my Bundle looks like, (2) is how any Sonata page looks like, what is wrong?

Reynier Perez Mira
eMail: reyn...@gmail.com, ad...@reynierpm.com
Website: http://www.reynierpm.com
Skype: reynierpm
Mobile: +58 424-180.56.09
1.png
2.png

Cassiano Tartari

unread,
Nov 27, 2013, 1:49:31 PM11/27/13
to sonata-users
Try to place this file in: app/Resources/SonataAdminBundle/views/standard_layout.html.twig

But I think that the right is in config

sonata_admin:
    templates:
        layout:  SonataAdminBundle::standard_layout.html.twig


Cassiano Valle Tartari
MSc. Computer Engineer

Tel: +55.48.84474818
Email: fal...@cassianotartari.eng.br
Site: http://www.cassianotartari.eng.br

QR Code


--
You received this message because you are subscribed to the Google Groups "sonata-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonata-users...@googlegroups.com.
To post to this group, send email to sonata...@googlegroups.com.
Visit this group at http://groups.google.com/group/sonata-users.
For more options, visit https://groups.google.com/groups/opt_out.

reyn...@gmail.com

unread,
Nov 27, 2013, 2:03:35 PM11/27/13
to sonata...@googlegroups.com
This is exactly how I have in config.yml so I don't know what is wrong

Reynier Perez Mira
eMail: reyn...@gmail.com, ad...@reynierpm.com
Website: http://www.reynierpm.com
Skype: reynierpm
Mobile: +58 424-180.56.09


Cassiano Tartari

unread,
Nov 27, 2013, 2:14:54 PM11/27/13
to sonata-users
So If you want to change the default you need to do:

sonata_admin:
    templates:
        layout:  CompanyYourBundle::standard_layout.html.twig


=====================================================================================

{# Company/YourBundle/Resources/views/standard_layout.html.twig #}
{% extends 'SonataAdminBundle::standard_layout.html.twig' %}
{% block sonata_page_content %}
    something
{% endblock %}

=====================================================================================

Place in app/Resources/SonataAdminBundle/views/standard_layout.html.twig and it will override the template.


Cassiano Valle Tartari
MSc. Computer Engineer

Tel: +55.48.84474818
Email: fal...@cassianotartari.eng.br
Site: http://www.cassianotartari.eng.br

QR Code


reyn...@gmail.com

unread,
Nov 27, 2013, 2:39:42 PM11/27/13
to sonata...@googlegroups.com
I think you didn't understand what I'm trying to do, let me explain better. I have already overwritten the default template as you suggest before, this means create a folder in app/Resources/SonataAdminBundle/views/standard_layout.html.twig, that works fine. Also I have this in my /app/config/config.yml:

sonata_admin:
    title: Portal Ingenieros
    templates:
        layout: SonataAdminBundle::standard_layout.html.twig
        ajax: SonataAdminBundle::ajax_layout.html.twig

Now I have a Bundle under /src/PI/CommonBundle/Resources/views/Informe/reporte.html.twig and that file has this content:


{% extends 'SonataAdminBundle::standard_layout.html.twig' %}
{% block sonata_page_content %}
    something
{% endblock %}


But it's not working as I said in first post, this is what I'm trying to figure out how to fix


Reynier Perez Mira
eMail: reyn...@gmail.com, ad...@reynierpm.com
Website: http://www.reynierpm.com
Skype: reynierpm
Mobile: +58 424-180.56.09


Cassiano Tartari

unread,
Nov 28, 2013, 5:44:46 AM11/28/13
to sonata-users
Where are you calling this template? Which arguments are you passing?

Cassiano Valle Tartari
MSc. Computer Engineer

Tel: +55.48.84474818
Email: fal...@cassianotartari.eng.br
Site: http://www.cassianotartari.eng.br

QR Code


reyn...@gmail.com

unread,
Nov 28, 2013, 6:28:32 AM11/28/13
to sonata...@googlegroups.com
I'm calling in my PICommonBundle Controller indexAction() and I,m not passing any parameters to it

Reynier Perez Mira
eMail: reyn...@gmail.com, ad...@reynierpm.com
Website: http://www.reynierpm.com
Skype: reynierpm
Mobile: +58 424-180.56.09


Cassiano Tartari

unread,
Nov 28, 2013, 6:32:12 AM11/28/13
to sonata-users
Maybe that's why it is not rendering all the stuff.

Take a look how is composed a default action from sonata crud controller to create yours.

Cassiano Valle Tartari
MSc. Computer Engineer

Tel: +55.48.84474818
Email: fal...@cassianotartari.eng.br
Site: http://www.cassianotartari.eng.br

QR Code


reyn...@gmail.com

unread,
Nov 28, 2013, 8:22:19 AM11/28/13
to sonata...@googlegroups.com
Where I should look for that code? /vendor/sonata-project/admin-bundle/Sonata/AdminBundle/Controller and then which controller? Or I miss?

Reynier Perez Mira
eMail: reyn...@gmail.com, ad...@reynierpm.com
Website: http://www.reynierpm.com
Skype: reynierpm
Mobile: +58 424-180.56.09


Cassiano Tartari

unread,
Nov 28, 2013, 8:30:11 AM11/28/13
to sonata-users
When you add the admin class as a service you choose which controller will be:

  sonata.admin.example:
    class: Company\MyBundle\Admin\ExampleAdmin
    arguments: [null, Company\MyBundle\Entity\Example, 'SonataAdminBundle:CRUD']
    tags:
        - { name: sonata.admin, manager_type: orm, group: Menu, label: Example }


This controller is: vendor/sonata-project/admin-bundle/Sonata/AdminBundle/Controller/CRUDController.php

Cassiano Valle Tartari
MSc. Computer Engineer

Tel: +55.48.84474818
Email: fal...@cassianotartari.eng.br
Site: http://www.cassianotartari.eng.br

QR Code


reyn...@gmail.com

unread,
Nov 28, 2013, 9:31:22 AM11/28/13
to sonata...@googlegroups.com
I'll need some help here since I can't get this to work, could you write a little example in how to extend this?

Reynier Perez Mira
eMail: reyn...@gmail.com, ad...@reynierpm.com
Website: http://www.reynierpm.com
Skype: reynierpm
Mobile: +58 424-180.56.09


Milena Kamińska

unread,
Jan 3, 2016, 4:59:08 AM1/3/16
to sonata-users
Maybe someone will read this :) Could you tell me how did you deal with overrides template per one Admin?

I added standard_layout.html.twig to app/Resources/AdminBundle/views this twig. After that created the custom twig (in MyBundle/views):
{% extends 'SonataAdminBundle::standard_layout.html.twig' %}

And nothing is happend.

In services I added something like that:
calls:
            - [ setTemplate, [standard_layout, MyBundle:JobOffer:findCandidate.html.twig]]

Could anyone help me?

discu...@webdevilopers.net

unread,
Jan 3, 2016, 8:46:12 AM1/3/16
to sonata-users
You are mixing the global standard layout with the per admin attempt. See "If you wish, you can specify custom templates on a per Admin mapping basis."

https://sonata-project.org/bundles/admin/master/doc/reference/templates.html#configuring-templates

services:
   
app.admin.post:
       
class: AppBundle\Admin\PostAdmin
       
tags:
           
- { name: sonata.admin, manager_type: orm, group: "Content", label: "Post" }
       
arguments:
           
- ~
           
- AppBundle\Entity\Post
           
- ~
       
calls:
           
- [ setTemplate, [edit, AppBundle:PostAdmin:edit.html.twig]]


Reply all
Reply to author
Forward
0 new messages