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 Answer 1

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
    Commented Nov 17, 2021 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.
    – 4uk4
    Commented Nov 17, 2021 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
    Commented Nov 17, 2021 at 11:00

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.