Twig fundamentals
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...