Creating templates with TWIG

Symfony has its own template engine called TWIG. It is a simple scripting language with a few tags and only three main rules:

  • Whatever goes between {% %} should be executed
  • Whatever is expressed via {{ }} should be printed
  • Whatever is enclosed by {# #} is just a comment

As we continue, we will see how to use TWIG to create sophisticated and dynamic templates based on our project needs. For now, let's just see what a TWIG file looks like.

The render() method from the previous topic has two parameters: the path to our TWIG template and its parameter. By default, all templates are in the app/Resources/views folder. If you go there, you will find another folder called default. That's why the middle part of the path parameter ...

Get Mastering Symfony now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.