ranlt / smarty-php

Automatically exported from code.google.com/p/smarty-php
0 stars 0 forks source link

passing array to a template within include #199

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. PHP code
$smarty->append('menu',array('menuitemtext1',array('action'=>'menuitemaction1',
'actionparams'=>'menuitemactionparams1'));
$smarty->append('menu',array('menuitemtext2',array('action'=>'menuitemaction2',
'actionparams'=>'menuitemactionparams2'));
$smarty->display('template1');

2. smarty template 1
{foreach from=$menu item=menuitem}
    {include file='template2' param1={$menuitem.0} param2={$menuitem.1} }
    {$menuitem.1.action} {*it works!*}
{/foreach}

3. smarty template 2
{$param2.action} {*throws error*}

What is the expected output? What do you see instead?

{$param2.action} generates 'Illegal string offset 'action'' PHP error as if 
param2 would be a string. But param2 is an array and it has an action member 
(see template 1) :(. 

What version of the product are you using? On what operating system?

v3, compile 4694 2013-01-03 21:13:14Z; Linux

Please provide any additional information below.

N/A

Original issue reported on code.google.com by peter.hu...@gmail.com on 13 Sep 2014 at 8:59

GoogleCodeExporter commented 9 years ago
You are passing the parameter wrong.

It must be:

{include file='template2' param1=$menuitem.0 param2=$menuitem.1}

Some like {$menuitem.0} is evaluated in a string and will not pass the subarray.

Original comment by Uwe.Tews@googlemail.com on 14 Sep 2014 at 10:31