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.
Add a comment
|
1 Answer
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) }}
-
Thanks it works! But it's printing a
#
behind the value for some reason. Do you know why? 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.– 4uk4Commented 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. Commented Nov 17, 2021 at 11:00