Break in Smarty's / Dwoo's foreach

hsz picture hsz · Jan 22, 2010 · Viewed 9.1k times · Source

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 ?

Answer

Darmen Amanbayev picture Darmen Amanbayev · Jan 22, 2010

You should put your logic in php, not in template. However, you can write your own 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}.