0

I'm looking to print out the url for a file in a Drupal File field in the twig template. I'm doing this inside a paragraph twig file.

I've followed a similar answers on stack overflow but to no joy.

The field is a File field with no other specific configuration.

<a href="{{ file_url(content.field_file.entity.uri.value) }}" class="download-file download-row file">...</a> 

I've tried setting the link display as URL to File as that's all I need, but it still wont render out the URL.

3
  • 3
    Does this answer your question? Get Image URL in Twig Commented Feb 10, 2021 at 16:18
  • I'm afraid I don't quite follow. I'm looking for a file (doc, pdf etc) not an image. And I'm doing this at paragraph twig level so I'd be using content.field_name. I've tried setting the link display as 'URL to File' as thats all I need, but it still wont render out the url. Commented Feb 10, 2021 at 16:22
  • 4
    There is no difference between images and files. And use the data object node.field_myfile... (or paragraph.field_myfile... if inside paragraph template) as source, not the render array content.field_myfile... Commented Feb 10, 2021 at 16:24

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.