使用Foreach的Smarty [英] Smarty using foreach

查看:16
本文介绍了使用Foreach的Smarty的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    {foreach from=$last_comments item=lastcomment name=myLoop}

        <dt class="{if $smarty.foreach.myLoop.first}first_item{elseif $smarty.foreach.myLoop.last}last_item{else}item{/if}"><a href="{$lastcomment.link}" title="{$lastcomment.name|escape:html:'UTF-8'}">{$lastcomment.name|strip_tags|escape:html:'UTF-8'|truncate:25:'...'}</a></dt>
        <dd class="{if $smarty.foreach.myLoop.first}first_item{elseif $smarty.foreach.myLoop.last}last_item{else}item{/if}">
            <div class="star_content clearfix">
                {section name="i" start=0 loop=5 step=1}
                    {if $lastcomment.grade le $smarty.section.i.index}
                        <div class="star"></div>
                    {else}
                        <div class="star star_on"></div>
                    {/if}
                {/section}
            </div>
            {if $display_title && $lastcomment.title}{if $maxchar_title}{$lastcomment.title|escape:html:'UTF-8'|truncate:$maxchar_title:'...'}{else}{$lastcomment.title|escape:html:'UTF-8'}{/if}{elseif $display_title && $display_notitle}{l s='No title'  mod='blocklastcomments'}{/if}<p>{if $maxchar_comment}{$lastcomment.content|escape:html:'UTF-8'|truncate:$maxchar_comment:'...'}{else}{$lastcomment.content|escape:html:'UTF-8'}{/if}</p><span class="customer">{if $lastcomment.customer_name}({$lastcomment.customer_name|escape:html:'UTF-8'}.){/if}</span>
        </dd>
    {/foreach}

我想循环访问$LAST_COMMENTS固定次数。如何实现此目标?

推荐答案

由于prestashop 1.5与Smarty 3一起工作,因此在满足条件时只需使用{Break}

{if $lastcomment@iteration==5}
    {break}
{/if}

这篇关于使用Foreach的Smarty的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆