简体   繁体   中英

How to insert json string into smarty template?

I prepare json string in php file

$groups_json = json_encode($groups);
$smarty->assign('groups', $groups_json);

How can I put it properly into in .tpl file like that

<script>
var groups = "{$groups}"; // <-- here

I have smarty 3

My issue was that smarty converted quotes and other stuff to html entities. The answer is to add nofilter parameter to the template variable

var groups = {$groups nofilter};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM