1

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.

6
  • 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?
    – cilefen
    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) }} Sep 16, 2022 at 16:16
  • Rendering an icon is no "functionality", this is a template. Write HTML code
    – Hudri
    Sep 16, 2022 at 16:58
  • @Hudri see template_preprocess_file_link() in file.module. 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
    Sep 16, 2022 at 17:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.