CMS Development

simonp
Mitglied

Scope of variable in for loop

lösung

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 Akzeptierte Lösung
John
Lösung
Stratege/Strategin | Platinum Partner
Stratege/Strategin | Platinum Partner

Scope of variable in for loop

lösung

try:

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


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

Lösung in ursprünglichem Beitrag anzeigen

2 Antworten
John
Lösung
Stratege/Strategin | Platinum Partner
Stratege/Strategin | Platinum Partner

Scope of variable in for loop

lösung

try:

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


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

simonp
Mitglied

Scope of variable in for loop

lösung

thankls john

0 Upvotes