The Twig Backlink extension builds a list of URL of the parents of the node based on the field name passed in the Twig twig_backlink extension parameter.
This extension will automatically build a list of parents when an Entity Reference field is used and referenced in the Twig file.
Usage
{{ twig_backlink('field_name') }}
You may wrap the twig_backlink extension with some verification to prevent PHP notices/warnings when there is no relation between a child and parent node:
{% set backlinks = twig_backlink('field_example') %}
{% if backlinks is defined %}
{% if backlinks is not null %}
{{ twig_backlink('field_example') }}
{% endif %}
{% endif %}Example
We may have two content types:
- Movie (with an Entity Reference field linked to Actor with machine name field_actors); this content type is the parent.
- Actor; this content type is the child.
In the node twig file of actors, we want to list all movies (parents) that the actor appears in automatically. So we add in the twig file:
{{ twig_backlink('field_actors') }}
We create a few actors and then for each movie we create, we reference the cast (actors) in the Actors field.
When viewing an actor node, all the movies the actors appears in will be displayed in a bulleted list of links pointing back to the movies the actor is staring in.
Requirements
- PHP ext-intl
- An Entity Reference field added to a node.
- Access to a node twig file that the themer can edit.
Soutien technique également offert en français.
Project information
- Project categories: Content display, Site structure
4 sites report using this module
- Created by xmacinfo on , updated
Stable releases for this project are covered by the security advisory policy.
Look for the shield icon below.
