views:

22

answers:

1

{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?

A: 

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.

JochenJung
{loop} in Dwoo is combination of {foreach} and {with}. If there's no {with} in Smarty 3 then there's no {loop} either.
Kamil Szot
In Smarty you just need foreach (now with), like above. Have you tried the code?
JochenJung
I know this code works but it forces me to invent name for variable to hold current element and forces me to access this element through that variable. Please take a look at my other question about same thing to see what I'm talking about: http://stackoverflow.com/questions/3942034/do-you-know-of-any-popular-php-template-engines-for-php-that-have-concept-of-curr
Kamil Szot