Twig in Drupal

Twig is a template engine for PHP.

Working With Twig Templates

Drupal allows you to override all of the templates that are used to produce HTML markup so that you can fully control the markup that is

Twig Template naming conventions

Drupal loads templates based on certain naming conventions. This allows you to override templates by adding them to your theme and giving

Comparison of PHPTemplate and Twig theming paradigms

This page compares PHPTemplate to Twig.

Discovering and Inspecting Variables in Twig Templates

When working with a Twig template file most variables are documented in the comments for the template file. However, when they are not, or

Debugging Twig templates

The Twig templating engine offers a debug tool.

Debugging compiled Twig templates

The Twig engine provides options for configuring debugging, automatic reloading (recompiling) of templates, and caching compiled templates

Locating Template Files with Debugging

To know which template is generating the markup for a particular element, you can use Twig's built in debug option. This option

Filters - Modifying Variables In Twig Templates

Filters in Twig can be used to modify variables. Filters are separated from the variable by a pipe symbol. They may have optional arguments

Functions in Twig templates

Twig provides a number of handy functions that can be used directly within templates.

Macros in Twig Templates

From the official Twig documentation: "Macros are comparable with functions in regular programming languages. They are useful to put often

Twig best practices - preprocess functions and templates

Follow these best practices to improve Drupal 8 theming performance, convert Drupal 7 theme calls, & allow more Twig template customization

Create custom twig templates for custom module

The general idea in Drupal 8 is that you want to avoid creating html directly in the PHP code of your custom module. You want this to go

Extending templates

Twig templates can be extended, retaining the original template but adding more to it.

Profiling a Twig template

How to test the speed of a Twig template using XHProf

Guide maintainers

joelpittet's picture