Jump to content

[Solved]Problem with smarty code help!


Recommended Posts

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

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

_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

×
×
  • Create New...