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 Fletcher08 Nov 2023
Using paragraph.getParentEntity() in Drupal Twig templates
In Drupal Twig templates, you can set a variable like paragraph_parent to the parent entity of a paragraph using the paragraph.getParentEntity() method. This is a common approach when you want to access the parent entity (e.g., a node) that contains the paragraph.  Here's how you can do it:{#...
Andrew Fletcher14 Oct 2023
Twig\Error\SyntaxError: Unexpected "spaceless" tag
Update Drupal to 10.1.x and I'm receiving the following errorTwig\Error\SyntaxError: Unexpected "spaceless" tag (expecting closing tag for the "macro" tag defined near line 2). in Twig\Parser->subparse() (line 2 of themes/custom/{theme}/templates/misc/filesize-macro.html.twig).The error message...
Andrew Fletcher19 Sep 2023
Twig\Error\SyntaxError: Unknown "filter" tag
Twig errorTwig\Error\SyntaxError: Unknown "filter" tag. in Twig\Parser->subparse() (line 6 of themes/custom/{theme}/templates/views/views-view-field--products--field_product_type.html.twig).Line 6 of the views-view-field--products--field_product_type.html.twig file is {% filter...