2

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

Kamil Szot
  • 17,436
  • 6
  • 62
  • 65

2 Answers2

0

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
  • 7,183
  • 12
  • 64
  • 113
  • {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 Oct 20 '10 at 08:45
  • In Smarty you just need foreach (now with), like above. Have you tried the code? – JochenJung Oct 20 '10 at 09:17
  • 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 Oct 20 '10 at 23:21
0

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

Kamil Szot
  • 17,436
  • 6
  • 62
  • 65