Im using the following Smarty code:
{foreach from=$entries key=i item=topic}
{if $topic.topic_style == question}
<li>
<a href="topic.php?id={$topic.id}">{$topic.title}</a>
</li>
{/if}
{/foreach}
How can i do the {foreach} a maximum of 10 times and then stop?
You can use index
and break
function:
{foreach from=$entries key=i item=topic name=foo}
{if $smarty.foreach.foo.index == 10}
{break}
{/if}
{if $topic.topic_style == question}
<li>
<a href="topic.php?id={$topic.id}">{$topic.title}</a>
</li>
{/if}
{/foreach}
Break function is described here:
Break in Smarty's / Dwoo's foreach
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With