Jump to content

Как Вывести Обернуть Каждые 3 Товара В Отдельный Div ?


Go to solution Solved by simpla24,

Recommended Posts

Как обернуть каждые 3 блока товара  <div class="product"></div> ?

 

Что бы вывод кода был такой 

 

<div class="clear-product">

<div class="product"></div>
<div class="product"></div>
<div class="product"></div>
</div>
 
<div class="clear-product">
<div class="product"></div>
<div class="product"></div>
<div class="product"></div>
</div>
 
Link to post
Share on other sites
  • Solution
<div class="clear-product">

  {foreach $products as $p}

 

    <div class="product"></div>

 

    {if $p@iteration%3 == 0}

    </div><div class="clear-product">

    {/if}

 

  {/foreach}

</div>

Link to post
Share on other sites

 

<div class="clear-product">
  {foreach $products as $p}
 
    <div class="product"></div>
 
    {if $p@iteration%3 == 0}
    </div><div class="clear-product">
    {/if}
 
  {/foreach}
</div>

 

Спасибо ! Помогло +

Link to post
Share on other sites

А Как сделать?

 

<div class="clear-all">

 

<div class="product"></div>
<div class="product"></div>
<div class="product"></div>
<div class="clear"></div>
 
<div class="product"></div>
<div class="product"></div>
<div class="product"></div>
<div class="clear"></div>
<div class="product"></div>
<div class="product"></div>
<div class="product"></div> 
<div class="clear"></div>
.... и тд
 
</div>
Edited by Textpatten
Link to post
Share on other sites

 

А Как сделать?

 

<div class="clear-all">

 

<div class="product"></div>
<div class="product"></div>
<div class="product"></div>
<div class="clear"></div>
 
<div class="product"></div>
<div class="product"></div>
<div class="product"></div>
<div class="clear"></div>
<div class="product"></div>
<div class="product"></div>
<div class="product"></div> 
<div class="clear"></div>
.... и тд
 
</div>

Нашел решение )

 

 

<div class="nn">
 
    {foreach $products as $product}
<!-- Товар--> {include file='tovar.tpl'} <!-- Товар (The End)--> 
   {if $product@iteration%3 == 0}    <div class="gh"></div>{/if} 
    
    {/foreach}
            
</div>
Link to post
Share on other sites

 

<div class="clear-product">
  {foreach $products as $p}
 
    <div class="product"></div>
 
    {if $p@iteration%3 == 0}
    </div><div class="clear-product">
    {/if}
 
  {/foreach}
</div>

 

Можно еще так:

 

 

{foreach array_chunk($products, 3, true) as $products_chunk}
	<div class="clear-product">
	{foreach $products_chunk as $product}
		<div class="product"></div>
	{/foreach}
	</div>
{/foreach}
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...