Views get total row count in views-view.html.twig I need to get the total rows count in views-view.html.twig file. So that I can loop through it and create the indicators required for my bootstrap carousel view block.

I tried the solution provided in this thread Drupal 8 Views get total row count in views-view-fields.html.twig but nothing seems to be working.

Can any one please guide me how its possible.
This can be achieved as follows. NB this outlines a simple approach which works. It can be finessed and improved upon by stripping our unnecessary divs, applying classes more elegantly, etc, but this will work:


Adding a views attachment display and attaching it to your main
display of the slides (display: after); 
Set this attachment with an ordered list display format with List class = carousel-indicators;
Add one custom text field (it will not be displayed so it does not really matter what this is); 
Set it to evaluate the same conditions as your main display (eg content filtered by a boolean "display in slider" = TRUE ... or whatever). This way number of bullets definitely = number of slides; 
Copy the core views-view-list.html.twig to your theme and override with your
display name (see api.drupal.org/api/drupal/core!modules!views!views.theme.inc/group/views_templates/8.3.x for general suggestions); 
Return the rows as follows:

{% for row in rows %}
     {% if loop.first %}
      &lt;li{{ row.attributes }} data-target="#carousel-example-generic" data-slide-to="{{ loop.index }}" class="active"&gt;{{ row.content }}&lt;/li&gt;
     {% else %}
      &lt;li{{ row.attributes }} data-target="#carousel-example-generic" data-slide-to="{{ loop.index }}"&gt;{{ row.content }}&lt;/li&gt;
     {% endif %}
    {% endfor %}


This gets the active class on the first item and includes the index number, thus matching the requirements at: getbootstrap.com/javascript/#carousel

Controls and required wrappers can be set simply in the views-view.html.twig:

 {% if rows %}


&lt;div id="carousel-example-generic" class="carousel slide" data-ride="carousel"&gt;

 {{ rows }}


&lt;!-- Controls --&gt;
`
(...etc..)

Slide wrapper and active class can be set in views-view--unformatted.html.twig for the slides themselves:

 `&lt;!-- Wrapper for slides --&gt;`


&lt;div class="carousel-inner" role="listbox"&gt;

{% for row in rows %}
   {% if loop.first %}
    &lt;div class ="active item"&gt;
    {{ row.content }}
    &lt;/div&gt;

{% else %}
   &lt;div class ="item"&gt;
    {{ row.content }}
   &lt;/div&gt;

{% endif %}
 {% endfor %}

&lt;/div&gt;&lt;!-- end slider wrapper --&gt;

Working example: http://wri.netuxosandbox.co.uk/en