Smarty echo array variable named "-" in title

I have a variable that in the PHP controller looks like

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

It passes fine in smarty, but when I try to show it in any of these ways, it shows either 0 (accepts minus as an operator, or 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 the array key in the controller?

+4
source share
1 answer

In your example, the links are "HTML-FORM-END" on your controller, but "HTML-FORM-BEGIN" is in your view, but I assume that this is not your problem, and both exist. How about this?

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

From what I can find, it seems that the only way to get into a multidimensional array in Smarty is through loops. Perhaps instead you can split your array into destinations in your controller to provide easy access:

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

and then you can refer to them in your template as follows:

 {$content_mods_HTML-FORM-BEGIN} {$content_mods_HTML-FORM-END} // etc. 
+1
source

Source: https://habr.com/ru/post/1301417/


All Articles