Is there anything like Dwoo-s {with} or {loop} in Smarty 3 or earlier?

折月煮酒 提交于 2019-12-24 04:03:04

问题


{with} and {loop} plugins in Dwoo template engine change default context for variable name resolution.

If in Dwoo you feed template:

{$arr.foo}
{with $arr} {$foo} / {$arr.foo} {/with}

with data:

array('arr' => array( 'foo' => 'bar' ))

it will output:

bar
bar / 

because second {$arr.foo} actually means {$arr.arr.foo} in global context.

Do you know how can I achieve similar effect in Smarty?

Is there some builit in functionality or third party plugin that might allow me to have this?

Do you have any idea how to build such a plugin if it does not exist?


回答1:


You have foreach to achive the loop:

{foreach from=$arr item=foo}
    <li>{$foo}</li>
{/foreach}

If you are however searching for a replacement of with, I'm afraid there is no similar command in Smarty.




回答2:


To my knowledge you can't achieve this effect in Smarty 3 or earlier.



来源:https://stackoverflow.com/questions/3940927/is-there-anything-like-dwoo-s-with-or-loop-in-smarty-3-or-earlier

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