Jump to content

divide list into multiple columns <ul> ?


rboyart
 Share

Recommended Posts

Hello,

 

Do you know how to divide a list into multiple columns <ul> </ul>  when using {foreach} in prestashop ?

 

This is my loop :

<ul>
{foreach from=$products item=product name=products}
<li>
{if isset($product.pack_quantity) && $product.pack_quantity}{$product.pack_quantity|intval|cat:' x '}{/if}<a href="{$product.link|escape:'htmlall':'UTF-8'}" title="{$product.name|escape:'htmlall':'UTF-8'}">{$product.name|truncate:35:'...'|escape:'htmlall':'UTF-8'}</a>
</li>
{/foreach} 
</ul>

Thanks

Share this post


Link to post
Share on other sites

Yes, that I Know. But my questions was, how to do multi-column for a long list every X items, not just one <ul>?

 

I try "mod" to do it :

 

 

{foreach from=$products item=product name=products}
{if $smarty.foreach.products.index % 40 == 0}
</ul>
{/if}
{if $smarty.foreach.products.index % 40 == 0}
<ul class="lista-products">
{/if} 
<li class="ajax_block_product {if $smarty.foreach.products.last}last_item{/if}">


{if isset($product.pack_quantity) && $product.pack_quantity}{$product.pack_quantity|intval|cat:' x '}{/if}<a href="{$product.link|escape:'htmlall':'UTF-8'}" title="{$product.name|escape:'htmlall':'UTF-8'}">{$product.name|truncate:35:'...'|escape:'htmlall':'UTF-8'}</a>

</li>


{/foreach}

This will make a <ul> every 40 list items but it's not very clean... 

Do you know a better way to do this?

 

Thanks

Share this post


Link to post
Share on other sites

Yes, that I Know. But my questions was, how to do multi-column for a long list every X items, not just one <ul>?

 

no you question was "Do you know how to divide a list into multiple columns <ul> </ul>  when using {foreach} in prestashop ?"

i just thought that you're askning about how to do this :)

 

 

method that you provided above (with $smarty.foreach.products.index % 40 == 0) is correct

why you said that it is unclean? when i want to achieve something similar im always using $variable % 2 == 0 and it works very well

Share this post


Link to post
Share on other sites

Sorry about my english I'm a spanish speaker, that's the confusion :)

 

I believe is unclean because :

{if $smarty.foreach.products.index % 40 == 0}
</ul>
{/if}
{if $smarty.foreach.products.index % 40 == 0}
<ul class="lista-products">
{/if}

There's two same "if" working to divide the list, so the first time in the loop :

- $smarty.foreach.products.index % 40 is 0

so it's going first, put a closing </ul>, next the opening <ul>, then the foreach loop with 40 items of the list, until next time the loop is "$smarty.foreach.products.index % 40 is 0" for closing the </ul> and start again....

 

There's the first closing </ul> created is wrong, not needed and because of the magic of the browsers we dont see any errors, but for real isn't clean.

 

Or am I wrong ?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More