Limiting a foreach loop to 4 iterations only

For discussion and questions related to CMS Specific templates and stylesheets (CSS), and themes. or layout issues. This is not a place for generic "I don't know CSS issues"
Post Reply
jazz
New Member
New Member
Posts: 4
Joined: Sun Feb 24, 2008 4:42 am

Limiting a foreach loop to 4 iterations only

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

Re: Limiting a foreach loop to 4 iterations only

Post 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
jazz
New Member
New Member
Posts: 4
Joined: Sun Feb 24, 2008 4:42 am

Re: Limiting a foreach loop to 4 iterations only

Post by jazz »

Thanks!
jazz
New Member
New Member
Posts: 4
Joined: Sun Feb 24, 2008 4:42 am

Re: Limiting a foreach loop to 4 iterations only

Post 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.
alby

Re: Limiting a foreach loop to 4 iterations only

Post 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
jazz
New Member
New Member
Posts: 4
Joined: Sun Feb 24, 2008 4:42 am

Re: Limiting a foreach loop to 4 iterations only

Post by jazz »

Great, thanks. It turns out the function I needed was get_root_alias.
Post Reply

Return to “Layout and Design (CSS & HTML)”