Page 1 of 1

Limiting a foreach loop to 4 iterations only

Posted: Sun Feb 24, 2008 4:49 am
by jazz
Hi,

I'm trying to make a "more articles" type of box for my content pages. I'm using a modded menu template to do this, so the call to the menu manager is as follows:

{menu template='minimalmenu' start_element="2.1" show_root_siblings="1"}

It will only show sibling articles, which is what I want.

The problem is, it is listing all articles. I want it to just show, say, the top 5 articles then a "View All" link. I'm trying to mod the minimalmenu template to do this, but I'm new to smarty and am having trouble.

Essentially, I want the foreach loop to only loop 4 times then quit. How can this be done?

Any help would be appreciated.

Thanks and regards,
Jazz

Re: Limiting a foreach loop to 4 iterations only

Posted: Sun Feb 24, 2008 11:40 am
by alby
jazz wrote: Essentially, I want the foreach loop to only loop 4 times then quit. How can this be done?
Look here:

Code: Select all

{foreach from=$myArray item=i name=foo}
 {if $smarty.foreach.foo.iteration < 5}
  .....
  loop
  .....
 {/if}
{/foreach}
Alby

Re: Limiting a foreach loop to 4 iterations only

Posted: Sun Feb 24, 2008 1:49 pm
by jazz
Thanks!

Re: Limiting a foreach loop to 4 iterations only

Posted: Sun Feb 24, 2008 3:21 pm
by jazz
Ok next problem I'm having.

At the end of the iterations, I'm tyring to display a "View All" link which links to the parent page of the pages I'm displaying in the menu.

So, I'm calling the menu template as follows:
{menu template='minimalmenu' start_element="2.1" show_root_siblings="1"}

In this minimalmenu template, I want to put in a hyperlink that links back up to what would essentially be start_element="2".

Is that possible?

Thanks.

Re: Limiting a foreach loop to 4 iterations only

Posted: Sun Feb 24, 2008 5:50 pm
by alby
jazz wrote: In this minimalmenu template, I want to put in a hyperlink that links back up to what would essentially be start_element="2".
This is as variable (get_parent_alias) in CGSimpleSmarty module

Alby

Re: Limiting a foreach loop to 4 iterations only

Posted: Sun Feb 24, 2008 6:12 pm
by jazz
Great, thanks. It turns out the function I needed was get_root_alias.