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 is a situation I had recently after upgrading to Drupal 10.4.0 and provides a clear resolution for the problem.
Accessing nested paragraph fields in Drupal: a step-by-step reference
The issue – I have a content type that includes an entity reference revisions field named field_introduction. This field points to a paragraph, which itself contains a text field also named field_introduction, of the type Text (formatted, long). How can I access the content stored in this paragraph's field_introduction field?
Using Twig {% extends %}
In Twig, the {% extends %} tag is used to inherit and extend the contents of another template. In the case you provided:
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:
Twig\Error\SyntaxError: Unexpected "spaceless" tag
Twig\Error\SyntaxError: Unknown "filter" tag
Twig error
Twig\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 upper|escape('html') %}
The actual Twig file code
Creating a node alias path in a twig file
Do you want to know how to add a node alias in a twig file? Rather than do the set up in a custom module or using your theme file.
To be able to create a node alias in a twig file you need to know the node.nid value. Obviously without it you have nothing to reference from. In this example, the node.nid value is extracted during a loop. A fairly standard loop such as
Displaying a content type that has a paragraph within a paragraph in a twig file
I want to create a content type that has a paragraph. Easy enough.
What happens when I want to extend this concept and have a paragraph within the first paragraph? Importantly, then display the second paragraph in a twig file.
How to create a content type that holds a paragraph within a paragraph and make it display in twig files?
Argument 1 passed to Drupal\Core\File\FileUrlGenerator::generateString() must be of the type string, null given
How do I generate URL by term_id (tid) or node_id (nid)
When you have an entity ID value such as node ID (nid) or taxonomy term ID, how can you create the alias in a twig file? In other words, instead of /taxonomy/term/{tid} I would like to get the alias I have defined for this, eg: /some/path/to/my/term.
In trying to find an answer you might have queried your search criteria using something like
twig canonical taxonomy path twig canonical entity path twig canonical node path