Search code examples
twigtimber

Passing PHP global variables via Twig/Timber


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.


Solution

  • 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 }}