Skip to main content

Drupal 9 twig: Get the url of a link field into string and the title of the link

This is how you can get the url of a field link rendered as a string (internal or external). 

<a href="{{ node.field_link.get(0).getUrl().toString() }}">{{ node.field_link.get(0).title }}</a>

 

twig