Hi everyone,

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__">
        __Title__
        __Image__
    </a>

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.

Comments

PHP OOPS’s picture

Yes you can manage it from views ui itself. steps are

  1. Add title, image, file and Custom Text field to your view.
  2. Edit Title, Image field and check exclude from display option and save.
  3. Edit File field and check exclude from display checkbox, In Formatter drop down select "URL to file" and save.
  4. Edit custom text field
    • Click to "REPLACEMENT PATTERNS"
    • 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.
  5. Save the view and now its ready.
heyow’s picture

Thank you very much.
It's exactly what I wanted.