|
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 |
olfedoss Smarty n00b
Joined: 24 Jul 2019 Posts: 1
|
Posted: Wed Jul 24, 2019 11:00 am Post subject: output of three elements from the loop with the condition |
|
|
How to display three points from an array with a condition?
The code below simply displays one third item and stops (total items - 10). Items 1 and 2 are hidden because they are empty. Where is the mistake?
{|foreach from=$basketsArray key="i" item="b" name="foo"|}
{|if (!empty($b.customProduct_ssilkanatovar8))|}
{|if $smarty.foreach.foo.index < 3|}
{|$b.name|}
{|/if|}{|/if|}
{|/foreach|} |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Jul 26, 2019 6:34 am Post subject: |
|
|
If you want to output items from array by 3, the easy way is to split array into chunks first.
Try something like
Code: | {foreach array_chunk($basketsArray, 3, true) as $foo}
// Print chunk decoration
{foreach $foo as $i => $b}
… // print elements from a chunk
{/foreach}
{/foreach} |
|
|
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
|