12 articles Twig & Doctrine

Rendering Twig templates from Symfony Repository without Using Dependency Injection (DIC)

Sometimes it's useful to access Twig templates from a Symfony repository, one could argue that this goes against a repository's role, but if you think of Twig template files or Twig strings perhaps grabbed from a database as data, then this coincides nicely with the function of a repo. These arguments aside, whatever your situation,…

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…