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.
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}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With