How to retrieve all Variables from a Twig Template?

前端 未结 14 1515
抹茶落季
抹茶落季 2020-12-08 00:24

Is it possible to retrieve all variables inside a Twig template with PHP?

Example someTemplate.twig.php:

Hello {{ name }}, 
your new email is {{ ema         


        
14条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-08 00:59

    After using duncan's answer for quite some time I finally found the "right" way to dump all twig variables of a template:

    {% dump %}
    

    That's it. All the variables available in the template will be dumped and in the dump section of the profiler, not in the middle of your html like with {{ dump() }}.

    if you put the contents of dump() into a variable:

    {% set d = dump() %}
    

    you 'll get all the variables but in "dump ready" html so it would be a pain to parse it.

    Hope that helps.

提交回复
热议问题