4

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
  • Today I learned smarty accesses multi-dimensional arrays with dots. Commented Apr 19, 2011 at 21:36

1 Answer 1

1

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.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.