tags:

views:

21

answers:

1

Hi,

i have an associative array and i am trying to get the first record with smarty.

In php i use current(array), but smarty dont seems to have current.

So i wrote the code below

{if is_array($browseProducts.data) }
    <ul class="products-grid">

        {foreach from=$browseProducts.data item=item}
            {assign var='image' value=''}
            {if is_array($item.images) }
                {php} $image=current($item.images); {/php} 
            {/if}   
        {/foreach}

    </ul>
{/if}

in {php} section current($item.images) gives Warning: current() [function.current]: Passed variable is not an array or object

The syntax is right so i guess the $item.images from smarty can not be read by {php}

Any way to pass $item.images to {php} section, or what.

Any suggestion to solve my problem?

+1  A: 
{$item.images.0}

should return the first element of the $item.images array.

So:

{if is_array($browseProducts.data) }
    <ul class="products-grid">

        {foreach from=$browseProducts.data item=item}
            {assign var='image' value=''}
            {if is_array($item.images) }
                {$item.images.0}
            {/if}   
        {/foreach}

    </ul>
{/if}
JochenJung