Skip to content

Instantly share code, notes, and snippets.

@webdevilopers
Created September 26, 2014 08:04
Show Gist options
  • Save webdevilopers/2e4455c69d258c5fdca9 to your computer and use it in GitHub Desktop.
Save webdevilopers/2e4455c69d258c5fdca9 to your computer and use it in GitHub Desktop.
Override list view twig template in SonataAdminBundle
# Acme\DemoBundle\Resources/config/admin.yml
services:
sonata.admin.foo:
class: Acme\DemoBundle\Admin\FooAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: "Foo", label: "Foo" }
arguments:
- ~
- Acme\DemoBundle\Entity\Foo
- ~
calls:
- [ setTemplate, [list, AcmeDemoBundle:FooAdmin:list.html.twig]]
<?php
namespace Acme\DemoBundle\Admin;
use Sonata\AdminBundle\Admin\Admin;
class FooAdmin extends Admin
{
public function getTemplate($name)
{
switch ($name) {
case 'list':
return 'Acme\DemoBundle:FooAdmin:list.html.twig';
break;
default:
return parent::getTemplate($name);
break;
}
}
}
# AcmeDemoBundle:FooAdmin:list.html.twig
{% extends 'SonataAdminBundle:CRUD:base_list.html.twig' %}
{% block list_header %}
Here is a list Foos:
{% endblock %}
@CaptainJojo
Copy link

Add function in FooAdmin is not utils :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment