Score:0

How to show a field in a view for another field?

il flag

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.

Score:1
cn flag

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?

Jorn Reed avatar
il flag
Thanks it works! But it's printing a `#` behind the value for some reason. Do you know why?
4uk4 avatar
cn flag
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.
Jorn Reed avatar
il flag
Yeah I tried, that doesn't work for me. Also I twig's dump() doesn't work, altough I enabled twig debugging etc.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.