Break in Smarty's / Dwoo's foreach

China☆狼群 提交于 2019-12-21 04:53:28

问题


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 ?


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/2116391/break-in-smartys-dwoos-foreach

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!