What is the best way to handle recursion in smarty?

后端 未结 4 1572
时光取名叫无心
时光取名叫无心 2020-12-17 00:28

I found a couple of ways to handle recursion in Smarty, mostly based on including templates into themselves, which seems like ridiculous waste of resources. I found one solu

4条回答
  •  粉色の甜心
    2020-12-17 00:58

    You might want to consider creating custom function/modifier/plugin for smarty. Pass the array to the custom function along with defining what is the template the function should use. If it is that simple, only to insert a text to certain place, load the template within function and in PHP work with the template using regexes/str_replace/...

    Or do it directly in PHP without using smarty templates, because all you need is h1, ul, li and p tags and to change the layout use CSS.

    Or if your concern is the overhead with opening and closing files in Smarty, estimate what is the amount of levels in 90% of cases and create template which will cover those 90%. For the rest use recursion by including the template itself...

提交回复
热议问题