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

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
Tantalus
New Member
New Member
Posts: 4
Joined: Mon Mar 19, 2012 8:26 am

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

Post 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. :(
jmcgin51
Power Poster
Power Poster
Posts: 1899
Joined: Mon Jun 12, 2006 9:02 pm

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

Post 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.
Jos
Support Guru
Support Guru
Posts: 4019
Joined: Wed Sep 05, 2007 8:03 pm

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

Post 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
Post Reply

Return to “CMSMS Core”