Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Howto generate json with smarty?

Tags:

In Smarty, is there a standard function or an easy way to generate json from an array, as json_encode() does in php?

I could not see it in Smarty documentation, wanted to ask here.

like image 870
Sinan Avatar asked Aug 16 '09 22:08

Sinan


1 Answers

This should work. The @ makes smarty run the modifier against the whole array, otherwise it does it for each element.

{$myarray|@json_encode}

If $escape_html is enabled, you will need to use nofilter:

{$myarray|@json_encode nofilter}
like image 120
Tom Haigh Avatar answered Sep 18 '22 11:09

Tom Haigh