0

I have twig template named views-view-field--banner--block_1--field-banner.html.twig Here I print <a href="">{{ output -}}</a> To put an anchor tag around an image field named field_banner. I also have another field named field_slider_banner_link that I want to print within the href="". But I have no clue how to get the value from that other field into this template.

1

If the template provides a row variable (check the available variables in the Twig comments) and is not a table:

views-view-field.html.twig:

{{ view.field.other_field.getvalue(row) }} 

See also How can I theme individual fields in a row?

3
  • Thanks it works! But it's printing a # behind the value for some reason. Do you know why?
    – Jorn Reed
    Nov 17 at 10:29
  • Don't know, but theming Views fields in templates is not always the best idea. Views is in the first place a UI tool. Did you try the linked topic? Seems to be about your use case.
    – 4k4
    Nov 17 at 10:52
  • Yeah I tried, that doesn't work for me. Also I twig's dump() doesn't work, altough I enabled twig debugging etc.
    – Jorn Reed
    Nov 17 at 11:00

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.