Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Break in Smarty's / Dwoo's foreach

Tags:

php

smarty

dwoo

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 ?

like image 413
hsz Avatar asked Jan 22 '10 09:01

hsz


2 Answers

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}.

like image 67
Darmen Amanbayev Avatar answered Oct 03 '22 19:10

Darmen Amanbayev


@Antonio: typical PHP developer retort, indeed :) Using Smarty largely depends on app requirements and developer/designer preferences. Here are some typical use case examples, and how Smarty plays a role:

http://www.smarty.net/use_cases

If you don't like it, don't use it. Shunning Smarty in general is just showing your ignorance for what it may offer for others.

like image 40
joe Avatar answered Oct 03 '22 20:10

joe