Twig (http://twig.sensiolabs.org) is the new template engine introduced to Drupal 8 and is a companion to Symfony, the new PHP framework that Drupal 8 is built on. Twig provides us with a fast and secure way to separate content from PHP logic in a manner that makes it easier for non-developers to work with templates. Before we begin working with Twig, let's first dive into the steps involved in enabling Twig debugging.
A Twig template outputs PHP with a template-oriented syntax using opening and closing curly brackets {{ ... }}. This syntax interprets the variable between the brackets and outputs HTML in its place. The following are three kinds of delimiters in Twig that trigger an evaluation to take place:
- The first is Twig commenting, which uses the comment tag {# ... #} to provide comments inline or around a section of HTML.
- Next is the print tag {{ ... }}, which is used to print the result of an expression or variable. The print tag can be used by itself or within a section of HTML.
- The third tag is to execute a statement such as conditional logic, looping structures, or the assignment of values to variables and is expressed by {% ... %}.
Each of the three delimiters will be used when we do any type of theming project in Drupal 8. We will find that they are just as simple as using any regular HTML element, and we will quickly be writing these tags.