Page 1 of 1

Missing {while} and {for}, is there any replacement?

Posted: Tue Mar 20, 2012 2:02 pm
by Tantalus
Hello,

I've to loop for 30 times in a news template (the sites requires 30 entrys for a automatic sliding). I've tried something like this:

{counter start=0 assign='index'}
{while $index < 30}
{foreach from=$items item=entry}
{if $index < 30}
// Output
{counter assign='index'}
{/if}
{/foreach}
{/while}

In my real code there also some stuff to deal with the situation, where $items is an array with zero entries. This loop should fill the output with exactly 30 entries. It might be, that there are just 26 entries. This should be used for a logo slider with 2 lines. I've found {while} and {for} in the smarty docu, but in cmsms it missing. :(

Re: Missing {while} and {for}, is there any replacement?

Posted: Wed Mar 21, 2012 3:10 am
by jmcgin51
Tantalus wrote:Hello,
I've found {while} and {for} in the smarty docu, but in cmsms it missing. :(
It is missing by design. You can add it in yourself, if you feel it would be useful on your site.

Re: Missing {while} and {for}, is there any replacement?

Posted: Wed Mar 21, 2012 1:14 pm
by Jos
Tantalus wrote:In my real code there also some stuff to deal with the situation, where $items is an array with zero entries. This loop should fill the output with exactly 30 entries. It might be, that there are just 26 entries. This should be used for a logo slider with 2 lines.
How about this:

Code: Select all

{* call max 30 news entries *}
{news number=30}

{* if there are less then 30 entries (var $itemcount), add default entries *}
{section name=foo start=$itemcount loop=30}
  {$smarty.section.foo.index}{* do whatever you want, now outputs the index number of the loop *}
{/section}
Reference:
http://www.smarty.net/docsv2/en/languag ... ection.tpl