17
I don't understand how that fixed the problem...
This code:
<{foreach item=article from=$block.articles name=tztz}>
<{if $smarty.foreach.tztz.index == 5}>
td><td>
<{/if}>
won't break a foreach loop. All it's doing is checking to see if the current index is 5, but there's no 'break' syntax to actually break the loop so it will keep doing interations to the very end while it continues to check if the index is still equal to 5, even though it may be way above 5.
Is there not any sort of 'break' syntax for Smarty? or a 'Goto' to try to get out of the loop?
I was trying to display a certain amount of items on the screen, but I wanted the loop to stop once it reached 3, but there's no way to break out of the loop when this condition is met.
EDIT: Nevermind, I found this on another site and it works. I'm going to go ahead and post it here in case someone else has the same problem as me:
Quote:
(From: http://qaix.com/php-web-programming/148-751-smarty-break-out-of-foreach-loop-read.shtml)
I think that guy means a {foreach} tag inside a template .
Well the answer is easy - such a function is missing. If you really
need it (normally such logic should be in your php scripts, not in your
templates...), write your own (compiler) plugins for that.
// compiler.break.php
function smarty_compiler_break($contents, &$smarty)
{
return 'break;';
}
?>
//compiler.continue.php
function smarty_compiler_continue($contents, &$smarty)
{
return 'continue;';
}
?>
Create these two files and put them into your plugins directory
(notice the naming convention compiler.xxx.php). Now, you should
be able to leave foreach and section loops with {break} and to leave
out one step with {continue}.