In Smarty, is there a standard function or an easy way to generate json from an array, as json_encode() does in php?
json_encode()
I could not see it in Smarty documentation, wanted to ask here.
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:
nofilter
{$myarray|@json_encode nofilter}
1.4m articles
1.4m replys
5 comments
57.0k users