I'm trying to override the views-view-unformatted.html.twig template by an unformatted view that includes a hidden Grouping field.
The default template includes this code:
{% if title %}
<h3 class="group-title">{{ title }}</h3>
{% endif %}
{% for row in rows %}
{%
set row_classes = [
default_row_class ? 'views-row',
]
%}
<div{{ row.attributes.addClass(row_classes) }}>
{{- row.content -}}
</div>
{% endfor %}
When I copy the default template into my theme, this generates the results I would expect:
When I try to modify the code by wrapping a div around the loop that fetches the rows, like this:
{% if title %}
<h3 class="group-title">{{ title }}</h3>
{% endif %}
<div class="group-content">
{% for row in rows %}
{%
set row_classes = [
default_row_class ? 'views-row',
]
%}
<div{{ row.attributes.addClass(row_classes) }}>
{{- row.content -}}
</div>
{% endfor %}
</div>
I get this output instead:
Note that the first two rows are wrapped in the group-content div, whilst the third row is now wrapped in a separate group-content div. There should obviously be only one group-content div, with all rows inside it.
My goal in overriding the default template is to put them all in a separate div, which I can't do from within the views settings, so the fact that overriding the template isn't working defeats the object of the exercise.
Any ideas why this is happening, and how to get around it?