Skip to content

Instantly share code, notes, and snippets.

@thamas
Last active December 5, 2018 13:23
Show Gist options
  • Save thamas/e9cb7aea753077c852cf0bc41456b87f to your computer and use it in GitHub Desktop.
Save thamas/e9cb7aea753077c852cf0bc41456b87f to your computer and use it in GitHub Desktop.
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