1

I have SonataBundle installed in my project and I need to alter standard_layout.html.twig shipped with it (viz. change block 'notice').

I place an empty file with same name into

/app/Resources/SonataAdminBundle/views

directory and this file is caught by Symfony, but now I want to make small changes in base template.
Is it possible? I've tried to place

{% extends 'SonataAdminBundle::standard_layout.html.twig' %}

in the first line of this file, but this results into a fatal error

Maximum function nesting level of '100' reached

Touki
  • 7,465
  • 3
  • 41
  • 63
NikitaObukhov
  • 193
  • 1
  • 2
  • 10
  • 1
    Did you placed `standard_layout.html.twig` aswell into your `/app/Resources/SonataAdminBundle/views` ? – DonCallisto Dec 10 '13 at 10:19
  • Yes I did. The file is caught by Symfony (I see empty page on Sonata routes) but when I put {% extends 'SonataAdminBundle::standard_layout.html.twig' %} in this file it results in infinite recursion (Maximum function nesting level of '100' reached error). – NikitaObukhov Dec 11 '13 at 02:52
  • So this is wrong because you have to insert only the template you want to override. In that way you're causing the loop – DonCallisto Dec 11 '13 at 13:06

3 Answers3

3

I found solution. Sonata allows one to configure which template to use for base layout.

# /app/config/config.yml
sonata_admin:
    title: Admin
    templates:
        layout:  SonataAdminBundle::base.html.twig

Now create file base.html.twig in app/Resources/SonataAdminBundle/views directory with the following content:

{% extends 'SonataAdminBundle::standard_layout.html.twig' %}

And it works.

NikitaObukhov
  • 193
  • 1
  • 2
  • 10
1

Increase the value of xdebug.max_nesting_level in your php.ini: http://xdebug.org/docs/all_settings#max_nesting_level

Pierre
  • 776
  • 6
  • 27
  • The answer is on SO too: http://stackoverflow.com/questions/10157649/maximum-function-nesting-level-of-100-reached-aborting – A.L Dec 10 '13 at 11:43
  • This is not a solution because this error means infinite loop. – NikitaObukhov Dec 11 '13 at 02:50
  • No this error not means infinite loop. 100 is really a low value as soon as you have some complex stuff. – Pierre Dec 11 '13 at 09:18
  • In my case it was an infinite loop. Actually > 100 nesting level means a very poor application architecture. – NikitaObukhov Dec 12 '13 at 02:40
  • Maybe you can take a look at this issue : https://github.com/FriendsOfSymfony/FOSCommentBundle/issues/238 . And more specifically at this comment of Stof (one of the largest contributor) : "IMO, it is. 100 is really a low value as soon as you have some complex stuff (it is unfortunate that the default is so low in XDebug)". So maybe you can send him an email to explain him how build a good application architecture... – Pierre Dec 12 '13 at 08:21
1

When you add /app/Resources/SonataAdminBundle/views/standard_layout.html.twig you essentially replace the original version so that everything that references SonataAdminBundle::standard_layout.html.twig (includes, extends, etc) now references your new version.

If you then use {% extends 'SonataAdminBundle::standard_layout.html.twig' %} you are extending the original, which is replaced by yours, which extends the original... Meaning that you are essentially extending itself over and over until the page dies.

As far as I know the only way to have this is to copy the whole of the original SonataAdminBundle::standard_layout.html.twig to /app/Resources/SonataAdminBundle/views/standard_layout.html.twig and then edit it how you want.

qooplmao
  • 17,622
  • 2
  • 44
  • 69