0

I have a block view, which is an unformatted list which prints my content type. All content has a field_file which I access using views-view--download--field-file.html.twig.

This prints a file link with the filename, like normal. But is it possible to replace for example document.txt with Document node title?

1 Answer 1

1

You can handle it directly from your View configuration using the "Rewrite results" option from field configuration.

  • Edit your View
  • Under the fields section, add your Content: title field, chexk "Exclude from display" and uncheck "Link to the content".
  • then, add your file field Content: my_file_field, choose the formatter "URL to file" and expand the Rewrite results section. Check Override the output of this field with custom text and use the textarea to write the replacement text. It accepts HTML and, most importantly, tokens (you can see the list of available tokens under the "Replacement patterns" section). In the end, something like <a href="{{ field_my_file_field }}">{{ title }}</a> would do the trick.
1
  • Thanks it works!
    – user108721
    Sep 28, 2022 at 14:41

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.