11 articles Twig & Doctrine

Symfony Twig: Accessing global values reference

Here is a reference list to access global values within Twig: For more Symfony Twig shortcuts, view the Twig Cheatsheet with recent updates added, a perfect reference for Symfony web developers.

Accessing Symfony global and server variables in Twig views through the “app” variable

In Symfony, you don't always have to actually pass values from your controllers to your Twig views.  Twig can actually pull global and server values directly through the super global "app" variable.  Most frequently, you can access these corresponding objects like Kernel, Request, Security and Session variables like so: Need more Twig tips?  View…

How to show or access cookie values in Symfony Twig views

Strange how obscure it is to find a clear example of how to just access or show the value of a cookie in Twig, so here it is! Twig is the templating engine that powers Symfony views.  Symfony is the PHP framework from Sensio Labs. If you are a company that uses open-source software…

Example of basic looping through array values in Symfony Twig

Cycle through an array of values for current year and 5 years into the future: The array "colors" would probably be better off defined in the controller then passed into the view here, but here's an example of how to set and initialize a new array in Twig. This can be handy if you…

Cookie basics for Symfony, Sensio Labs PHP framework

In Symfony, here is how you "get cookies": Don't forget to include the class path: Setting cookie values in Symfony is pretty straight forward, the thing to know is that since Symfony processes so much in its front controllers you can set cookies deeper into your code than other methods where headers are…