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