Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List all Twig templates used in the current request

Tags:

twig

symfony

I'm using Symfony2 with Twig templating engine.

Is there any way to output a list of all Twig templates files loaded in the current request, including the ones loaded through extends, include, etc.?

That would make my life much easier when overriding third-party bundles' blocks, but I can't find a way to do it.

like image 434
pagliuca Avatar asked Jan 14 '14 09:01

pagliuca


People also ask

Which Twig template used in Drupal is?

Twig is a template engine for PHP and it is part of the Symfony2 framework. In Drupal 8 Twig replaces PHPTemplate as the default templating engine. One of the results of this change is that all of the theme_* functions and PHPTemplate based *. tpl.


2 Answers

I've been looking for such a tool for a long time but never found it... The debug options of twig are very limited, and there is no tool in the sf2 dev bar dedicated to it...

I always add twig or html comments on top of each of my templates to get an idea of where I am and why during development or on the final page.

like image 100
np87 Avatar answered Sep 30 '22 08:09

np87


You can try this code, it puts filenames in HTML like this:

<!-- START templatename.html.twig -->
...
<!-- END templatename.html.twig -->

I know, that it is not a good solution, but it is better than nothing.

like image 45
Invis1ble Avatar answered Sep 30 '22 07:09

Invis1ble