solved Limiting Foreach

gary.moncrieff
gary.moncrieff
@garymoncrieff
11 years ago
865 posts
Hey Guys

The only way I have found so far to limit the number of entries returned by the smarty foreach command is to set a counter and use an if statement.

Is there any other way?

Thanks
updated by @garymoncrieff: 11/17/14 12:22:41AM
brian
@brian
11 years ago
10,149 posts
Jamroom uses Smarty templates, so all the documentation here:

http://www.smarty.net/docs/en/

is applicable. Specifically:

http://www.smarty.net/docs/en/language.function.foreach.tpl

you would use the "iteration" along with a break.

Hope this helps!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
gary.moncrieff
gary.moncrieff
@garymoncrieff
11 years ago
865 posts
Thanks will look into that.
michael
@michael
11 years ago
7,791 posts
more info would help out. What are you iterating over? If its the items returned by a {jrCore_list} call then you can set how many you want in the initial call.

eg:
{jrCore_list module="jrAudio" limit="5" template="custom_template.tpl"}

then in
/skins/your-skin/custom_template.tpl
{if isset($_items) && is_array($_items)}
 {foreach $_items as $key => $item}
   //do stuff here.  There will be a max of 5 items
 {/foreach}
{/if}

Like that.

Tags