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 are setting certain display options in the view that’s not tied to any data or logic that would be used anywhere but inside your views.

Aaron Belchamber has written 243 articles

Leave a Reply

Your email address will not be published. Required fields are marked *