banense Posted January 27, 2012 Share Posted January 27, 2012 Good morning, I have thic code that show all suppliers in a list: <ul class="products-list"> {assign var='suppliers' value=Supplier::getSuppliers()} {foreach from=$suppliers item=supplier name=supplier_list} <li class="{if $smarty.foreach.supplier_list.last}last{elseif $smarty.foreach.supplier_list.first}first{else}item{/if}"><a href="{$link->getsupplierLink($supplier.id_supplier, $supplier.link_rewrite)}" title=""><img src="{$img_sup_dir}{$supplier.id_supplier|escape:'htmlall':'UTF-8'}.jpg" alt="{$supplier.name|escape:'htmlall':'UTF-8'}" /></a></li> {/foreach} </ul> I need show only 10 supplier for example. Using in_array i can make this ??. Example {assign var="my_array" value="1,2,3,4,5,6,7,8,9,10"|@explode:","} {if in_array($supplier.id_supplier,$my_array)} <li><a href="{$link->getsupplierLink($supplier.id_supplier, $supplier.link_rewrite)}" title=""><img src="{$img_sup_dir}{$supplier.id_supplier|escape:'htmlall':'UTF-8'}.jpg" alt="{$supplier.name|escape:'htmlall':'UTF-8'}" /></a></li> {/if} Please I'm new somebody help me ??? Link to comment Share on other sites More sharing options...
tomerg3 Posted January 28, 2012 Share Posted January 28, 2012 It's best to create the array in php and pass it to the template. What exactly is the problem with your code, is it not printing at all? Link to comment Share on other sites More sharing options...
banense Posted January 30, 2012 Author Share Posted January 30, 2012 Hi tomerg, exactly, my code don't print nothing, i don't know if the code is 100% correct. You can helpme ??? Link to comment Share on other sites More sharing options...
_matis_ Posted January 30, 2012 Share Posted January 30, 2012 Hi banense, try to use {counter} : <ul class="products-list"> {assign var='suppliers' value=Supplier::getSuppliers()} {counter start=0 print=false name=idx} {foreach from=$suppliers item=supplier name=supplier_list} {counter} {if $idx <= 10} <li class="{if $smarty.foreach.supplier_list.last}last{elseif $smarty.foreach.supplier_list.first}first{else}item{/if}"><a href="{$link->getsupplierLink($supplier.id_supplier, $supplier.link_rewrite)}" title=""><img src="{$img_sup_dir}{$supplier.id_supplier|escape:'htmlall':'UTF-8'}.jpg" alt="{$supplier.name|escape:'htmlall':'UTF-8'}" /></a></li> {/if} {/foreach} </ul> or use iteration: <ul class="products-list"> {assign var='suppliers' value=Supplier::getSuppliers()} {foreach from=$suppliers item=supplier name=supplier_list} {if $smarty.foreach.supplier_list.iteration <= 10} <li class="{if $smarty.foreach.supplier_list.last}last{elseif $smarty.foreach.supplier_list.first}first{else}item{/if}"><a href="{$link->getsupplierLink($supplier.id_supplier, $supplier.link_rewrite)}" title=""><img src="{$img_sup_dir}{$supplier.id_supplier|escape:'htmlall':'UTF-8'}.jpg" alt="{$supplier.name|escape:'htmlall':'UTF-8'}" /></a></li> {/if} {/foreach} </ul> Link to comment Share on other sites More sharing options...
banense Posted January 30, 2012 Author Share Posted January 30, 2012 Tx _matis_ im going to test right now !! Link to comment Share on other sites More sharing options...
banense Posted January 30, 2012 Author Share Posted January 30, 2012 _matix_ the iteration work fine and only show the quantity. But for example is i need show only the supplier with id_supplier : 102,14,41,150 how i said to smarty to show only those ??? Thanks for your time and sorry for my english Link to comment Share on other sites More sharing options...
shacker Posted January 30, 2012 Share Posted January 30, 2012 before that you need to show, and inside the foreach, put {if $supplier.id_supplier eq "102" or $supplier.id_supplier eq "14"} and so on Link to comment Share on other sites More sharing options...
banense Posted January 30, 2012 Author Share Posted January 30, 2012 Tx shacker now work fine.. thank you very much Link to comment Share on other sites More sharing options...
shacker Posted January 30, 2012 Share Posted January 30, 2012 your welcome. change title to solved please Link to comment Share on other sites More sharing options...
Recommended Posts