rboyart Posted September 30, 2013 Posted September 30, 2013 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 More sharing options...
vekia Posted September 30, 2013 Posted September 30, 2013 just use </ul> and <ul> inside this foreach Share this post Link to post Share on other sites More sharing options...
rboyart Posted September 30, 2013 Posted September 30, 2013 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 More sharing options...
vekia Posted September 30, 2013 Posted September 30, 2013 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 More sharing options...
rboyart Posted September 30, 2013 Posted September 30, 2013 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 More sharing options...
rboyart Posted September 30, 2013 Posted September 30, 2013 well, I added : $smarty.foreach.products.first != true Thanks V Share this post Link to post Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now