How to display an item list from a twig template

117 views
Skip to first unread message

Richard

unread,
Oct 23, 2012, 5:14:59 AM10/23/12
to sonata...@googlegroups.com
Hi,

I designed my homepage/layout to show :
- my logo/app title/sidebar
- a href in this sidebar routing to my admin page (standard Sonata:Core:Dashboard) to manage all my items ("Book", "Category", "Reader" for example)
- and I want to display in the center of this homepage, the sonata list of my item "Book"

=> In my twig template, I have to know specifically the route to my item Book/list. How can I do this ?

Is there a better way to do what I want ?

Thanks for your help ;-)

Richard

unread,
Oct 24, 2012, 9:13:42 AM10/24/12
to sonata...@googlegroups.com
Nobody can help me ? :-(

Perhaps I'm not clear enough with my explanations. If so, I can explain a bit more.

jonben

unread,
Oct 24, 2012, 9:16:38 AM10/24/12
to sonata...@googlegroups.com
In some templates, i use soemthing like :
{{ path('admin_yourapp_yourbundle_yourentity_routename', {'id': object.id}) }}
For AcmeDemoBundle the route could be admin_acme_demo_book_list

I find this out by trying this in the console, it gives all routes registered, including thos of sonata admin :
php app/console router:debug

Richard

unread,
Oct 24, 2012, 11:28:33 AM10/24/12
to sonata...@googlegroups.com
Thanks for your answer.

In twig templates, the use of {{ path('my_route') }} returns the url. It's a good way when I want to add a href in my template.
But I have to display the content instead of the hyperlink.

I found the render twig function, which can be used to call a controller's action, like {% render "MyAppBookBundle:Book:list" %}
And so, the listAction in my controller could be :
public function listAction()
    {
        return $this->redirect($this->generateUrl('admin_myapp_bookbundle_book_list'));
    }

But I got the above error :
An exception has been thrown during the rendering of a template ("Error when rendering "http://dev.localhost/app_dev.php/" (Status code is 302).")

Any idea ? or another way ?

Richard

unread,
Oct 25, 2012, 2:52:58 AM10/25/12
to sonata...@googlegroups.com
Another info :

In an another AdminController (which extends CRUDController instead of Controller), the same type of call just works well :

public function saveAction()
    {
        ......

        return $this->redirect($this->generateUrl('admin_myapp_bookbundle_book_edit', array('id' => $book->getIdbook())));
    }


So I tried to implement my listAction function in a similar controller, but I got this error now :
An exception has been thrown during the rendering of a template ("There is no `_sonata_admin` defined for the controller `MyApp\BookBundle\Controller\BookAdminController` and the current route `_internal`")

Richard

unread,
Oct 25, 2012, 3:24:25 AM10/25/12
to sonata...@googlegroups.com
In fact, this error is fired even if my saveAction function is not implemented.

I think that the twig cannot communicate with my BookAdminController, but why ?
I don't understand this error message :-(

Any help would be appreciate.
Reply all
Reply to author
Forward
0 new messages