Reputation: 6553
I have set up my Admin class to render a custom template:
public function getTemplate($name)
{
switch ($name)
{
default:
case 'list':
return 'MyBundle:Admin:list.html.twig';
break;
return parent::getTemplate($name);
break;
}
}
This is working OK. I can enter some html in my template file and it renders OK. However, I want to extend the existing templates from the admin bundle as I only want to make some minor changes for this entity.
I've added the following to my template file:
{% extends 'SonataAdminBundle:CRUD:base_list.html.twig' %}
But this gives me the following error:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 77 bytes)
Can anyone tell me what I am doing wrong?
Upvotes: 0
Views: 3265
Reputation: 3070
I'm not sure if you are doing anything 'wrong' (besides the weird case syntax that doesn't do what I assume you think it does, see http://php.net/manual/en/control-structures.switch.php and scroll down to section describing the importance of 'break' statements).
It does seem like it's possible put symfony in an infinite loop when extending templates. I've seen this with a couple of templates. I haven't figured out exactly what triggers it, but I think it has something to do with bundle inheritance using EasyExtends. In my application I had a child sonata-admin bundle:
class ApplicationSonataAdminBundle extends Bundle
{
/**
* {@inheritdoc}
*/
public function getParent()
{
return 'SonataAdminBundle';
}
}
I then had overridden the standard_layout.html.twig with just the contents:
{% extends "SonataAdminBundle::standard_layout.html.twig" %}
This was causing "SonataAdminBundle::standard_layout.html.twig" to be loaded an infinite number of times because the template seems to effectively be extending itself.
Assuming your setup is similar to mine. I suspect that the only way to try to do what you are trying to do is to use a different template name (e.g. "my_standard_layout.html.twig") and then set that template as the application wide default as described here: https://sonata-project.org/bundles/admin/master/doc/reference/templates.html#configuring-templates
Upvotes: 0
Reputation: 2317
Your switch/case is incorrect.
It should be:
public function getTemplate($name)
{
switch ($name) {
case 'list':
return 'MyBundle:Admin:list.html.twig';
break;
default:
return parent::getTemplate($name);
break;
}
}
Upvotes: 3