CMS Development

simonp
Member

Scope of variable in for loop

SOLVE

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;

0 Upvotes
1 Accepted solution
John
Solution
Top Contributor | Platinum Partner
Top Contributor | Platinum Partner

Scope of variable in for loop

SOLVE

try:

Loop length outside of loop {{ module.image_gallery|length }}


I like kudos almost as much as cake – a close second.

View solution in original post

2 Replies 2
John
Solution
Top Contributor | Platinum Partner
Top Contributor | Platinum Partner

Scope of variable in for loop

SOLVE

try:

Loop length outside of loop {{ module.image_gallery|length }}


I like kudos almost as much as cake – a close second.

simonp
Member

Scope of variable in for loop

SOLVE

thankls john

0 Upvotes