Insert html in views every nth element
In twig you can use |batch().

For example to group the view in groups of 5 and add a div container around each group:

views-view-unformatted.html.twig

{% for group in rows|batch(5) %}
  &lt;div class="group"&gt;
  {% for row in group %}
    &lt;div{{ row.attributes }}&gt;
      {{ row.content }}
    &lt;/div&gt;
  {% endfor %}
  &lt;/div&gt;
{% endfor %}