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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.