Skip to content

Instantly share code, notes, and snippets.

Last active June 9, 2022 18:32
What would you like to do?
Get file url in node for Drupal 8 twig template
{# Get URL of single file field #}
{{ node.field_file.entity.uri.value }}
{# Get URL of multi file field #}
{{ node.field_file['#items'].entity.uri.value }}
{# Trun into link #}
{{ file_url(node.field_file.entity.uri.value) }}
{# Check if there is at least one value #}
{% if node.field_file[0] %}
// Do something...
{% endif %}
Copy link

frazras commented Apr 11, 2019

If you want to get the full url for internal URLs eg: private:// use
{{ file_url(node.field_file.entity.uri.value) }}

Copy link

@frazras ... Thanks for your clarification also. Helped a lot.

Copy link

I love it, thanks!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment