Skip to main content

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:

{# Get the parent entity (e.g., node) of the paragraph #}
{% set paragraph_parent = paragraph.getParentEntity() %}
{# Now you can access properties of the parent entity #}
{{ paragraph_parent.title.value }}

In this example, paragraph_parent will contain the parent entity, and you can access its properties, such as title, by chaining the property names as shown in the comment.

This assumes that you are using the Paragraphs module in Drupal to manage structured content and that you are working within a Twig template associated with the paragraph field. The getParentEntity() method is specific to the Paragraphs module and allows you to access the parent entity of the paragraph, typically a node.

Please note that the exact variable names and structure may vary depending on your specific Drupal setup, so consult your theme and module documentation to ensure you're using the correct variables and methods.

Related articles

Andrew Fletcher11 Feb 2025
Webpack build process and theme automation improvements
The Drupal theme configuration has undergone recent changes made to the Webpack configuration, SCSS and JavaScript handling, and automation of updates to the orw.libraries.yml file in the custom Drupal theme. These changes are designed to improve the build process, enhance maintainability, and...
Andrew Fletcher22 Jan 2025
Removing a missing module in Drupal
Occasionally, a Drupal site may display a warning about a module being "Missing or invalid." This issue occurs when a module is marked as installed in the configuration but is no longer present in the file system. A common example is the `fakeobjects` module, which is associated with CKEditor 4 and...