foreach does not run full, only runs 1 time

Asked

Viewed 72 times

-1

good afternoon, anyone has any idea why this foreach does not rotate 3 times, and wheel only 1?

$pag = 3; inserir a descrição da imagem aqui

  {foreach from=$pag item=pg}
     <div class="fotos-flex active">      
        {foreach from=$photos item=p}
           <div class="fotos-item">
              <img src="img/galeria/1-EXCHANGEDEVELOPMENTPROGRAM- 
               GROUP-  
               2016.JPG">
              <p>Exchange Development Program Group - 2016</p>
          </div>
        {/foreach}
     </div>
  {/foreach} 
  • And why would it run three times?

  • from=$pag, where $pag = 3.

  • put the image code disturb the understanding. it seems that yours is beginning with the value of 3, it is not that?

  • the initial value is 0 and should go up to 3. as well as the other foreach where $photos = 13, but it runs normally at 13 times.

  • 1

    @Virgilionovic code added in question.

  • 1

    The value of from shouldn’t it be an eternal object? It seems to me that it makes no sense to pass a number (but I never used Smarty)

  • https://www.smarty.net/docsv2/pt_BR/language.function.foreach.tpl I was reading here ... if you’ve seen it before

Show 2 more comments

1 answer

2


The noose 'foreach' is not used to iterate over a scalar. The foreach is used to take each element of a simple associative matrix.

To iterate over scalars use simple loop for:

  {for $pg=1 to $pag}
     <div class="fotos-flex active">      
        {foreach from=$photos item=p}
           <div class="fotos-item">
              <img src="img/galeria/1-EXCHANGEDEVELOPMENTPROGRAM- 
               GROUP-  
               2016.JPG">
              <p>Exchange Development Program Group - 2016</p>
          </div>
        {/foreach}
     </div>
  {/for} 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.