I'm trying to accomplish this simple thing but cannot find a way to do it. If someone could guide me a little bit because I'm going inside deep crazy methods and classes, but I'm sure I'm going the wrong way and there's a simple way to accomplish this :)

I have a view block, that displays these fields :

  • Content: Title (the title)
  • Content: Image (Image)
  • Content: Pdf (File Upload)

So, the title, the image and the file upload are displayed.

I would like to output something like this :

<a href="__link_to_my_pdf__">

Is there a way to do this through the view management ? If not, what could be the right way ? Twig ? Preprocess ? Module ?

I tried through a views-view--myviewblock.html.twig to get the variables inside {{rows}}, but spent 4 hours and failed.

Thanks in advance.

  • Have you tried using Field Rewrites inside the View? This should be pretty easy at least in D7. Not much experience with D8 views sorry if this is misleading
    – Beebee
    Commented May 19, 2017 at 11:24

2 Answers 2


Thanks for the link, I'll read it. I finally got an answer on drupal.org that suits perfectly. The idea is to use the "Custom text" field :

  • Add title, image, file and Custom Text field to your view.
  • List item
  • Edit Title, Image field and check exclude from display option and save.
  • Edit File field and check exclude from display checkbox, In Formatter drop down select "URL to file" and save.
  • Edit custom text field


    • Here you can find tokens for title, image and file fields. E.g. {{ title }} fir Title field and {{ field_image }} for image field.
    • Copy {{ title }} {{ field_image }} and paste it to Text.
    • Then click to "REWRITE RESULTS"
    • Check "Output this field as a custom link" and enter File field token {{ field_my_file }} to "Link Path" textfield. Save this field.
    • Save the view and now its ready.

For output like this u need to use template suggestions and custom twig template for specific view. See: The Power of Extending Twig Templates

Your Answer

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

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