Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

output of three elements from the loop with the condition

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: Russian
View previous topic :: View next topic  
Author Message
olfedoss
Smarty n00b


Joined: 24 Jul 2019
Posts: 1

PostPosted: Wed Jul 24, 2019 11:00 am    Post subject: output of three elements from the loop with the condition Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Fri Jul 26, 2019 6:34 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: Russian All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP