So for the longest time I was using the following line of code to get urls instead of relying on drupals raw output. The main reason being I need an <a> tag to wrap several elements.

{{ item.content['#paragraph'].field_home_slider_button_link.0.value.uri }}

Inside of a field.

For a quick minute I contemplated just removing the entity:, however I'd really like to understand what's happening here and if there's a way to tell drupal I want the actual url in either twig or some setting?


You have to use .url instead of .uri, like this:

{{ item.content['#paragraph'].field_home_slider_button_link.0.url }}

I don’t think this works on older versions of Drupal 8, so if it doesn’t work you can try this:

{{ item.content['#paragraph'].field_home_slider_button_link.0['#url'] }}
| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.