开发者

Arrays in smarty?

                    <div id="favorite-first" class="">
                    {foreach from=$arrSection key=k item=v}
                        {if $k==$selectedSection}
                            {$v}
                        {/if}
                    {/foreach}
                    </div>
                        <div id="favorite-toggle"><br></div>
                        <div id="favorite-inside" class="slideUp">
                            {foreach from=$arrSection key=k item=v}
                    开发者_运维知识库        {if $k==$selectedSection}
                            {else}
                            <div class="favorite-action" id="{$k}"><a href="javascript: section_submit({$k});">{$v}</a></div>
                            {/if}
                            {/foreach}
                        </div>

If $arrSection array returns only one value (i.e $k). I need to hide div (favorite-toggle,favorite-inside) How can i do this in smarty


If $arrSection array returns only one value

{if count($arrSection) eq 1}
    there is only one item
{else}
    there is > one or zero items    
{/if}


If you give the "foreach" a name argument you can access certain foreach properties:

{foreach from=$arrSection key=k item=v name=NAME}

Let's say the number of iterations in total:

$smarty.foreach.NAME.total

Then you now how often smarty will loop and if it's in your case only one time.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜