json
User 69e88e27
发布于:2025-09-10
json
解释
将 JSON 字符串解析为 Hash
或 Array
。
示例
{{ "{\"a\":\"123\"}" | json }}
to_json
解释
将 Array
和 Hash
类型值转换为 JSON 字符串。
在liquid页面中使用时请注意结合escape
使用
示例
{% comment %}
获取page下两层nav_tree数据,并通过to_json + escape 输出至html中,提供给 stimulusjs: turbo-nav-tree controller使用
{% endcomment %}
<div
data-controller="turbo-nav-tree"
data-turbo-nav-tree-nav-tree-value='{{ page | nav_tree: 2 | to_json | escape }}'
data-turbo-nav-tree-depth-value='0'
data-turbo-nav-tree-current-path-value='{{ page.path }}'
data-turbo-nav-tree-link-turbo-value="false"
>
</div>