Howto generate json with smarty?

前端 未结 5 1200
醉话见心
醉话见心 2020-12-05 18:43

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 docume

5条回答
  •  伪装坚强ぢ
    2020-12-05 19:32

    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}
    

提交回复
热议问题