How to var_dump variables in twig templates?

后端 未结 14 1482
滥情空心
滥情空心 2020-12-22 17:43

View layer pattern where you only present what you have been given is fine and all, but how do you know what is available? Is there a \"list all defined variables\" function

14条回答
  •  一生所求
    2020-12-22 18:28

    So I got it working, partly a bit hackish:

    1. Set twig: debug: 1 in app/config/config.yml
    2. Add this to config_dev.yml

      services:
          debug.twig.extension:
              class: Twig_Extensions_Extension_Debug
              tags: [{ name: 'twig.extension' }]
      
    3. sudo rm -fr app/cache/dev

    4. To use my own debug function instead of print_r(), I opened vendor/twig-extensions/lib/Twig/Extensions/Node/Debug.php and changed print_r( to d(

    PS. I would still like to know how/where to grab the $twig environment to add filters and extensions.

提交回复
热议问题