I'm trying to access the functionality of the file-link.html.twig template that comes with the classy theme so that I can have the file-type icons automatically appear next to the file links.

enter image description here

I've tried using the file_url and link functions in twig, but with no success.

Here's an example of what my file_url looks like {{ file_url(node.field_agenda_files_upload.entity.uri.value) }}

This just outputs something like /sites/default/files/2020-07/file.pdf

I'm new to Drupal, so please be kind.

  • Can you explain in a little more detail what you mean by "access the functionality of" some template file? Are you trying to change what Classy does? Are you implementing a different template altogether but trying to show these icons?
    – mona lisa
    Commented Sep 16, 2022 at 15:05
  • Sorry yes, I have created a new page template. If I output the contents of page.content, the files show up with the icons. However, if I'm trying to figure out how to get the same functionality when using file_url(node.field_agenda_files_upload.entity.uri.value) }} Commented Sep 16, 2022 at 16:16
  • Rendering an icon is no "functionality", this is a template. Write HTML code
    – Hudri
    Commented Sep 16, 2022 at 16:58
  • @Hudri see template_preprocess_file_link() in file.module. Commented Sep 16, 2022 at 17:08
  • 1
    You might find what you are looking for in the Twig tweak module. It has a {{ drupal_field(...) }} operator, which renders a complete field template. See cheat sheet
    – Hudri
    Commented Sep 16, 2022 at 17:28


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.