Skip to content

Instantly share code, notes, and snippets.

@rvizena
Created May 20, 2022 01:06
Show Gist options
  • Save rvizena/2f32c28643c162f640916e0a60c25335 to your computer and use it in GitHub Desktop.
Save rvizena/2f32c28643c162f640916e0a60c25335 to your computer and use it in GitHub Desktop.
Drupal 9: require the exact URL from the link reference field
You might be using a link field on your entity type, and if so, you might find yourself in a position where you require the exact URL from the link reference field.
{{ content.field_custom_link.0['#url'] }}
If you need the title, use this instead:
{{ content.field_custom_link.0['#title'] }}
Be sure to switch out the bolded text above for the machine name of your custom link field.
source: https://createdbycocoon.com/knowledge/get-url-or-title-link-field-drupal-twig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment