Skip to content

Instantly share code, notes, and snippets.

@StevenGFX
Forked from leahtard/node.twig.html
Last active November 27, 2018 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StevenGFX/6ac75cb596b0d35fd7153c58cf973383 to your computer and use it in GitHub Desktop.
Save StevenGFX/6ac75cb596b0d35fd7153c58cf973383 to your computer and use it in GitHub Desktop.
Get file url in node for Drupal 8 twig template #drupal8 #twig
{# 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 %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment