0
votes

i need include php and file path in array.

controller

$object[0]['id'] = 1;
$object[0]['path'] = '/home/path/for/file/file.php';

$static_path[0] =  '/home/path/for/file/static_path.php'; 

$this->smarty->assign(array(
'object' =>     $object,
'static_path' =>    $static_path
)); 

in .tpl - this throw error Fatal error: Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template... and Notice: Undefined index: path in /home/web/tools/smarty/sysplugins/smarty_internal_compile_include_php.php(61) : eval()'d code on line 1

{foreach from=$object item=value}
 {include_php file=$value['path']} // trhow error msg
 {$value['path']} // this show string path correctly
{/foreach}

in .tpl - this is Ok

 {include_php file=$static_path[0]} //incude correctly

I want use foreach i need use var for array key.

1

1 Answers

0
votes
$object = array(
  array(
    'id' => 1,
    'path' => '/home/path/for/file/file.php'
  )
);

// I'm not sure about this
$this->smarty->assign(array(
  'object' => $object
));

// May be the coorect way is, depending on template
$this->smarty->assign('object' => $object);