2

I'm trying to loop through rows in a views-view template, but I can't seem to kint or dump anything out to help me in doing so.

I've tried following various other answers, such as:

Again, without any success.

Usually I'd create a views-view-fields template, and access my fields via fields.title.content for example. I need to loop through them via the views-view template, as I'm needing to do some checks, taking into account values of some of the previous row's fields.

How can I access a rows fields when looping through rows in my views-view template?

1 Answer 1

1

In your case you should be using views-view-fields.html.twig instead of views-view-unformatted.html.twig file.

Views fields template will iterate on all rows of result. Your views-view-fields.html.twig should contain below code -

<div> <a class="view-row" href="{{variable-to-print-path }}"> <img src="{{ image-path }}"> <h3>{{ fields.title.content</h3> </a> </div> 

You can check the fields array by using kint function like - {{ kint(fields) }}

Check for image path and anchor path variable from output of kint function.

If you want to do this in views-view-unformatted.html.twig, then you can access the field values like below -

{% for row in rows %} {% set photo = file_url(row['content']['#row']._entity.field_page_photo.entity.fileuri) %} <li><img src={{ photo }} class="img-responsive img-circle"></li> {% endfor %} 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.