Accepted answer

Find the xdebug.ini file:

$ locate xdebug.ini

In my case the file is /etc/php5/conf.d/20-xdebug.ini. Open it and add this line:

xdebug.max_nesting_level = 1000

Don't forget to restart the FPM server.


In my case, I had to increase the amount of memory used by PHP in php.ini to 512MB. Also, I made a composer update on the site root folder to update the default settings generated by Symfony.


if increasing xdebug.max_nesting_level = 1000 failed check namespace is correct

eg: namespace App\Entities; but folder name in lower case app

then entity should contain namespace as namespace app\Entities;


Just sharing a little tips to new Twig developers who might be interested to understand the "What is causing.." part of the question.

Obvisouly in the original question the max nesting level is rather low (100) and as some comments mention, it might be too low for normal circumstances.

However, if one increases the level to, say 256, 512 or even 1000 as adviced above and still hit the same error, then perhaps the most potential thing to look at would be the template inheritance. (The extends keywords on the first line of the templates)

This is especially the case with projects where you have templates in multiple locations.

Imagine an example project structure:

── plugins
   ├── your-plugin
   |   ├── views
   |   │   ├── base.twig
   │   │   ├── special-element.twig
   │   │   ├── some-other-element.twig
── theme
   ├── base.twig
   ├── index.twig
   ├── sub-page.twig

The plugin has a template base.twig which extends the base.twig under the theme. But if the template locations are not correctly configured, the templates might end up extending itself again and again causing the infinite loop.

How to check if this is the case? I'd be happy to hear about more accurate solutions, but one can start - for debugging purposes only - as simple as referring to the parent templates with the full server paths:

{% extends "/var/www/path-to-your-template/" %}

If it starts to work with absolute paths, then you can be quite sure there is something wrong with the template paths. Read more about it here: Twig Template Naming and Locations


it is an error code that causes an infinite loop, but it happens from time to time that treatment without error exceeds the 100 calls nested functions.

To correct this, open the php.ini, xdebug section and add the following line (putting what you want instead of 150)

xdebug.max_nesting_level = 150

Related Query

More Query from same tag