Scope of variable in for loop

SOLVE
Highlighted
New Contributor

I am trying to number of images created by a module as define by loop.length value

 

i trying th following:

 

<div id="a">
    {% for item in module.image_gallery %}
              {% set no_Images = loop.length %}
             <img src="{{ item.src }}" alt="{{ item.alt }}" >

              <h3>Loop length with loop = {{ no_Images }}</h3>
     {% endfor %} 

</div>

<h3>Loop length  outside of loop= {{ no_Images }}</h3>

 

But i dont seem to be able to get the value outide of the loop

 

for now i using jquery to find the length;

var imgCount = $("img").length;

Reply
0 Upvotes
1 Accepted solution

Accepted Solutions
Highlighted
Esteemed Contributor | Platinum Partner

try:

Loop length outside of loop {{ module.image_gallery|length }}
2 Replies 2
Highlighted
Esteemed Contributor | Platinum Partner

try:

Loop length outside of loop {{ module.image_gallery|length }}
Highlighted
New Contributor

thankls john

Reply
0 Upvotes