Book Image

Extending Symfony2 Web Application Framework

By : Sebastien Armand
Book Image

Extending Symfony2 Web Application Framework

By: Sebastien Armand

Overview of this book

Table of Contents (13 chapters)

Twig


By default, Symfony ships with the Twig templating system. Twig is incredibly powerful and out of the box. The possibilities offered by blocks, extending templates, including templates, and macros are huge and will be enough for most cases. There are cases where you still need something more though, and an extension for Twig is the only elegant way of doing so.

Twig offers five different ways to create extensions:

  • Globals: This lets you define some global variables that are available in all templates. You could access them like any other variable.

  • Functions: This will let you write {{my_function(var)}}.

  • Tests: These are specific functions that return Boolean values and can be used after the is keyword in templates.

  • Filters: They modify the output of an output tag.

  • Tags: This will let you define custom Twig tags.

Some of the pages on our website will require some JavaScript in them to make them a bit more dynamic or simple to use. The form to create a meetup for organizers will definitely use...