S
S
Sergey Valitov2015-08-14 18:06:32
PHP
Sergey Valitov, 2015-08-14 18:06:32

How to output array element in Smarty?

Hello! There is this Smarty template:

{if $smarty.get.oid}
    {include file=fend.catalog__object__view.tpl}
{else}
    {catalog__define_sid sid=$sid assign=csid sss=$sss}
    {if $csid}
        {counter start=0 print=false}
        <div id="navi_3">
        {foreach from=$sss[$sid] item=i key=key}
            {counter assign=lnk_cnt}
            <a href="{$php_self}?sid={$i->g('uid')}&csid={$i->g('id')}{if $smarty.get.type}&type={$smarty.get.type}{/if}"{if $i->g('id') == $csid} class="selected"{/if}{if $i->g('id') == $csid || $i->g('oc') == 0} onClick="return false;"{/if}{if $i->g('oc') == 0} class="disabled"{/if}>{$i->g('tit')} <span class="s1">({$i->g('oc')}) <b>ЗДЕСЬ ЭЛЕМЕНТ МАССИВА</b></span></a>
            {if $lnk_cnt != count($sss[$sid])}
                <span class="s2">>></span>
            {/if}
        {/foreach}
        </div>
        {catalog__load__by_sid sid=$csid assign=os}
    {else}
        {if $sid==94 || $sid==95 || $sid==67 || $sid==68}
            {catalog__load__by_sid sid=$sid assign=os}
        {else}
            {catalog__load__by_ss ss=$sss[$sid] sid=$sid assign=os}
        {/if}
    {/if}
    {if $os} 
        {catalog__option__load__all assign=opts}
        {catalog__option__value__load__all assign=ovs}
        {catalog__image__load__by__objects objects=$os assign=is}
        {catalog__sync os=$os opts=$opts ovs=$ovs is=$is}
        {table_colomns from=$os item=i tpl='fend.catalog__object__list__item.tpl' columns=2 table_styles='id="cat"' td_styles='class="cat_item"'}
    {else}                       
    	<div style="padding: 10px;">{lang v=admin.catalog__no_items}</div>
    {/if}
{/if}

On the 10th line of the code (between tag B) you need to display the value. On the page, I specify $tpl->assign_by_ref('count', $count), that is, I give the template a direct link to the count variable. Good. But I can't print this array $count in the template so that the output index of the array is = {$i->g('id')}, i.e. $count[ $i->g('id') ] the template is just not output. The $i variable is taken from foreach, it's clear here .. but why the value is not displayed is not clear. Who can help with advice? I hope I explained clearly.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Cat Anton, 2015-08-14
@27cm

In Smarty 3 it should work like this:
www.smarty.net/docs/en/language.syntax.variables.tpl
Alternatively, try this:

{assign var="id" value=$i->g('id')}
{$count.$id}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question