Passing PHP global variables via Twig/Timber

馋奶兔 提交于 2021-02-11 12:48:02

问题


According to https://stackoverflow.com/a/19554524/6450661, standard Twig provides a method via {{ app.request }} that I can use to pass $_GET, $_POST, $_SESSION, etc. variables.

Using Timber, is there a similar method? I can use Timber\URLHelper's get_params() method to access $_GET variables, but that's about all I can seem to find.


回答1:


I looked through the source code and at least found the answer for $_GET and $_POST variables, so here it is if it helps anyone.

To access $_POST variables, use this:

{{ request.post.name_of_var }}

To access $_GET variables, use this:

{{ request.get.name_of_var }}


来源:https://stackoverflow.com/questions/56810653/passing-php-global-variables-via-twig-timber

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!