Faced a problem. Perhaps I am doing wrong ... The bottom line is this. There is a menu and it has 8 menu items!

<ul> {foreach $arr AS $a} <li>{$a.name}</li> {if $a@iteration % 4 == 0}</ul><ul>{/if} {/foreach} </ul> 

The problem is that in the end I get 3 ul. Those. it turns out that when the number of cycles reaches 4, then the previous ul is closed and the next ul opens ... Well, it ultimately generates 3 ul, which, in principle, is logical, based on the code. The question is how to remove the last empty ul? More precisely, yes, how to break correctly so that there is no such joint?

    2 answers 2

    It's simple:

     <ul> {foreach $arr AS $a} <li>{$a.name}</li> {if $a@iteration % 4 == 0 && $a@iteration!=$arr|count}</ul><ul>{/if} {/foreach} </ul> 
    • Well, thank you! - drop_off

    what? And why so much UL?

     <ul> {foreach $arr AS $a} <li>{$a.name}</li> {if $a@iteration % 4 == 0}</ul>{/if} {/foreach} 
    • Well, see the result of your code. Added </ ul> at the end of the blank. Those. when the number of iterations reaches 4, it adds </ ul>. In this case, 8 points. The iterations are generally the same 8. The output will be <ul> {foreach $ arr AS $ a} <li> {$ a.name} </ li> {if $ a @ iteration == 4} </ ul> <ul> {/ if} {/ foreach} </ ul> then there will be only one division. Well, this is taking into account that there will always be 8 points. - drop_off