How to debug what variables are needed in a template

Viewed 42

We want to change the way we do the frontends in symfony and we'd like some level of "reflection":

We want the system to be able to detect "Template displayProduct.html.twig needs xxxx other file, defines yyyy block and uses the zzzz variable".

I would like a command similar to:

php bin/console debug:template displayProduct.html.twig

that responds something like this:

Template: displayProduct.html.twig

Requires: # And tells us what other files are needed
    - widgetPrice.html.twig
    - widgetAvailability.html.twig

Defines: # And tells us what {% block xxxx %} are defined
    - body
    - title
    - javascripts_own
    - javascripts_general

Uses these variables: # <= This is the most important for us now
    - productTitle
    - price
    - stock
    - language

We are now visually scanning complex templates for needed variables and it's a killer. We need to automatically tell "this template needs this and that to work".

PD: Functional tests are not the solution, as we want to apply all this to dynamically generated templates stored in databases, to make users able to modify their pages, so we can't write a test for every potential future unknown template that users will write.

Does this already exist somehow?

0 Answers
Related