tags:

views:

227

answers:

1

Hi, I have variable that in PHP controller looks like

$data['content']['mods']['HTML-FORM-END']['html']

It is passed nicely in smarty, but when I try to show it any of these ways, it shows either 0 (assumes minus as operator and does some math), or says "unrecognized tag"

{$data.content.mods.HTML-FORM-BEGIN.html}
{$data.content.mods['HTML-FORM-BEGIN']['html']}
{$data.content.mods.HTML-FORM-BEGIN.html}
{$data.content.mods.HTML-FORM-BEGIN.html}

How can i print it without renaming array key in controller?

+1  A: 

Your example references 'HTML-FORM-END' in your controller but 'HTML-FORM-BEGIN' in your view but I'll assume that isn't your issue and both exist. How about this?

{$data[content][mods][HTML-FORM-BEGIN][html]}

From what I can find it appears that the only way to get down into a multi-dimensional array in Smarty is with loops. Perhaps instead you could split your array into assigns in your controller to provide easy access:

foreach($data['content']['mods'] as $key => $values) {
  $smarty->assign('content_mods_' . $key, $values['html'];
}

and then you could reference them in your template like this:

{$content_mods_HTML-FORM-BEGIN}
{$content_mods_HTML-FORM-END}
// etc.
Cryo