Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to access path from Link field in Twig template of Drupal 8 Field Group
{#
This is from a component based (Pattern Lab) custom Drupal theme.
_banner.twig is the actual component, a modified version of the HTML element Field Group template.
It contains a link component, the url of that is the banner_link_path variable.
The banner group contains a banner copy subgroup and it contains a Link field.
We get the path from that link field.
It's intended to use with internal paths, have'n tried with external urls (yet).
#}
{% set banner_link_route = element.group_banner_copy.field_banner_link.0['#url'].routeName %}
{% set banner_link_params = element.group_banner_copy.field_banner_link.0['#url'].routeParameters %}
{% set banner_link_src = path(banner_link_route, banner_link_params) %}
{% include "@organisms/banner/_banner.twig" with {
banner_link_path: banner_link_src,
} %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment