|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
benhamilton Smarty n00b
Joined: 10 Apr 2019 Posts: 1
|
Posted: Wed Apr 10, 2019 6:58 am Post subject: Return first x items in array, return items after x |
|
|
Hi all,
I'm new to using Smarty, and I have a template where I'm wanting the first 25 items of the array returned on the first page, and then the remaining ones on the second page.
The code I have currently is below, but I'm getting a series of blank lines (being total array length less 25) after the first 25 array entries on the first page, and a series of blank lines (being 25) before the remaining entries on the second page. I'm sure there is a tidier way of doing this that produces just the 25 rows on the first page and remaining on the second page. How do I do that?
On Page One I have:
Code: |
{foreach from=$crt_certificates_prd_products_1 item=IDENTIFIER}
{if $IDENTIFIER@index lt 25}
{$IDENTIFIER@index} - {$IDENTIFIER.name}
{elseif $IDENTIFIER@index gte 25}
{break}
{/if}
{/foreach}
|
Then on Page Two I have:
Code: |
{foreach from=$crt_certificates_prd_products_1 item=IDENTIFIER}
{if $IDENTIFIER@index lt 25}
{continue}
{elseif $IDENTIFIER@index gte 25}{$IDENTIFIER@index} - {$IDENTIFIER.name}
{/if}
{/foreach}
|
I've not found anything in the forum that has answered this, but will happily go read any posts you can point me to,
thanks in advance,
Ben.[/code] |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
|
Back to top |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Sun Apr 21, 2019 5:54 pm Post subject: |
|
|
This effect could be caused by Smarty honoring line endings after the control structure tags. If so, you may need to run the tags together:
Code: | {foreach from=$crt_certificates_prd_products_1 item=IDENTIFIER}{if $IDENTIFIER@index lt 25}{$IDENTIFIER@index} - {$IDENTIFIER.name}
{* don't actually need this {elseif $IDENTIFIER@index gte 25}{break} *}{/if}{/foreach} |
You might also try a simple {for} loop:
Code: | {for $i=0 to count($crt_certificates_prd_products_1) max=25}
{$i} - {$crt_certificates_prd_products_1[$i].name}
{/for}
{for $i=25 to count($crt_certificates_prd_products_1)}
{$i} - {$crt_certificates_prd_products_1[$i].name}
{/for} |
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|