tags:

views:

592

answers:

2

About break

foreach ( $data as $k => $v ) {
  if ( $k == 4 ) {
    break;
  }
}

every one knows.

Is there something similar in Smarty's or Dwoo's {foreach} function ?

+2  A: 

You should put your logic in php, not in template. However, you can write your won compiler plugin:

function smarty_compiler_break($contents, &$smarty){
   return 'break;';
}

and save it to compiler.break.php in your plugins directory.

Now in template you can use {break}.

Darmen
A: 

Don't use smarty if possible :)

AntonioCS
I do not use. :) I use only `Dwoo`. About solution - it is very similar in `Dwoo`. ;)
hsz
I think it's matter of taste in high-performance systems, but I a small environment, yes, agree.
Darmen
@Darmen: Either big or small, smarty is horrible. It tries to replicate php ifs, loops. etc. Why would you use something like that when you can simply use php. Not saying you shouldn't use a template system, just don't use smarty as a template system :)
AntonioCS