Skip to main content

In Twig, the {% extends %} tag is used to inherit and extend the contents of another template. In the case you provided:

{% extends "filed--text.html.twig" %}

This means that the current template is extending the content of the template file named "filed--text.html.twig." The contents of the extended template will be used as a base, and the current template can override or add to specific blocks defined in the base template.

 

A breakdown of the elements

{% extends "filed--text.html.twig" %} This tag specifies that the current template extends the content of "filed--text.html.twig."
When you extend a template, you often have the option to override specific blocks defined in the base template. For example, if "filed--text.html.twig" contains blocks like {% block content %}...{% endblock %}, you can provide your content for that block in the extending template.

This mechanism is commonly used in Twig for creating modular and maintainable templates, especially in scenarios where you have a base template that defines the overall structure, and specific templates extend and customise parts of that structure.

Related articles

Andrew Fletcher07 Jan 2025
Resolving Twig syntax errors in Drupal
The release of Drupal 10.4.0 sees stricter validation rules being applied to Twig templates, which can result in unexpected errors after an upgrade. One such issue involves the use of regular expressions within Twig's matches operator, leading to syntax errors that can break template rendering.This...