I have created a custom views-view-field template and added some custom html and views field similar to this
<div class="{{ fields.my_text_field.content }}">
{{ fields.my_media_field.content }}
</div>
The trouble I am having is that I want to add classes on certain rows only. Similar to below
<div class="{{ fields.my_text_field.content }} not-row-2">
{{ fields.my_media_field.content }}
</div>
<div class="{{ fields.my_text_field.content }} is-row-2">
{{ fields.my_media_field.content }}
</div>
<div class="{{ fields.my_text_field.content }} not-row-2">
{{ fields.my_media_field.content }}
</div>
In the views-view template I can run a loop and check the count and add a class using code similar to below, but then this class is in a different html wrapper. Not in the same wrapper as {{ fields.my_text_field.content }}.
{% if (loop.index == 2 ) %}
{% set rowclass = 'is-row-2' %}
{% else %}
{% set rowclass = 'not-row-2' %}
{% endif %}
<div class="{{rowclass}">
{{ row.content }}
</div>
{% endfor %}
How can I add a class to the child (row.content
) based on the row index of the parent at views-view-field. Thanks