Simplifying complex {if}{else} statements in {foreach} loops
Posted: Mon Aug 25, 2014 10:22 am
An easy way to exclude items is to put one {if} conditional statement, an action and close the {/if} at the beginning of the loop, eg:
Then when the loop encounters an entry that meets the condition, it immediately moves on to the next entry.
You can also shorten {foreach} processing times by making the loop stop once it meets the first instance of a condition, eg:
Code: Select all
{foreach from=$items item='entry'}
{if $entry == 'something' || or $entry < 15}
{continue}
{/if}
<p>do whatever with all the other entries.</p>
{/foreach}
You can also shorten {foreach} processing times by making the loop stop once it meets the first instance of a condition, eg:
Code: Select all
{foreach from=$items item='entry'}
{if $entry == 'something' }
<p>Hello {$entry}</p>
{break}
{/if}
{/foreach}