如何限制循环量
How to limit the amount of the loop
我是新手 smarty.This 一段代码会循环所有的列表,但我只想要10个项目,有没有办法在smarty中解决这个问题?谢谢!
<ul>
{section name=list loop=$list.list}
<li><span><a href="/?page=article_detail&co_sn={$list.list[list].co_sn}">{$list.list[list].co_title|truncate:20:"...":true}</a></span></li>
{/section}
</ul>
设置max
属性:
<ul>
{section name=list loop=$list.list max=10}
<li><span><a href="/?page=article_detail&co_sn={$list.list[list].co_sn}">{$list.list[list].co_title|truncate:20:"...":true}</a></span></li>
{/section}
</ul>
这个和其他 Smarty 部分属性设置可以在 Smarty Section Docs
中找到
我是新手 smarty.This 一段代码会循环所有的列表,但我只想要10个项目,有没有办法在smarty中解决这个问题?谢谢!
<ul>
{section name=list loop=$list.list}
<li><span><a href="/?page=article_detail&co_sn={$list.list[list].co_sn}">{$list.list[list].co_title|truncate:20:"...":true}</a></span></li>
{/section}
</ul>
设置max
属性:
<ul>
{section name=list loop=$list.list max=10}
<li><span><a href="/?page=article_detail&co_sn={$list.list[list].co_sn}">{$list.list[list].co_title|truncate:20:"...":true}</a></span></li>
{/section}
</ul>
这个和其他 Smarty 部分属性设置可以在 Smarty Section Docs
中找到