Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to assign a array of a value to param in Smarty?

Tags:

In my php code.

$version_config = array( 
    "list" => array(
        "123"
    ),
... other params
)   
$this->getView()->assign('version_config', $version_config);
$this->getView()->assign('version_list', $version_config['list']);

In my tpl code,

{assign var="version_list2" value="{$version_config.list}"}

{$version_list2} is a string values "Array" while {$version_list2} is an array. Do I need some more operations to encode {$version_list2} to an array?

like image 440
ZeroZerg Avatar asked Dec 30 '16 02:12

ZeroZerg


1 Answers

The double quotes are converting $version_config.list array to string "Array" just as "{$version_config['list']}" in PHP.

Also, there is no need for curly braces in the value. Simply pass the variable in the value parameter:

{assign var="version_list2" value=$version_config.list}
like image 136
Ruslan Osmanov Avatar answered Oct 14 '22 04:10

Ruslan Osmanov