Question

I want to assign an associative array in a smarty-template.

my code s far:

  {assign var='bild' value=','}
  {foreach from=$bilder item=item name=foreach_assArray}
      {assign var=name value=$item->field.name}
      {assign var=bild value=['$name'=>'$item']}
    {/if}
  {/foreach}

I found this on: http://www.smarty.net/forums/viewtopic.php?p=79092#79092 .
Some how it doesn't work. I want the array 'bild' like a hashmap for a later usage (something like <img src={pagr_url page=$bild.$name>).

Does anyone have some ideas how i could get it work?

Edit: before i forget: i use Smarty2, not version 3

Was it helpful?

Solution

I'm fairly sure you can't do anything of the sort in Smarty 2, barring the use of {php}{/php} inside the template itself: http://www.smarty.net/docsv2/en/language.function.php.tpl -- but that's not what you're looking for.

It's easy in Smarty 3 though.

The syntax in the link you provided ['foo'=>'bar',...] is Smarty 3 syntax.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top