怎么在 Liquid 中解析调用的富文本类型的元字段?

在 Liquid 中调用富文本类型的元字段前端输出的是JSON 数据,应该怎么解析?
{{ product.metafields.custom.product_contenu_text }}
前端输出:

{"type":"root","children":[{"type":"heading","level":3,"children":[{"type":"text","value":"La cryolipolyse, comment ça marche ?"}]},{"type":"paragraph","children":[{"type":"text","value":"La cryolipolyse est une méthode minceur qui fonctionne en refroidissant la graisse sous la peau jusqu'à la geler."}]}]}

尝试:

{% assign content = product.metafields.custom.product_contenu_text %}
{% if content.type == "root" %}
{% for child in content.children %}
{% if child.type == "heading" %}
{% assign heading_level = child.level | default: 3 %}
<h{{ heading_level }}>{{ child.children[0].value }}</h{{ heading_level }}>
{% elsif child.type == "paragraph" %}
<p>{{ child.children[0].value }}</p>
{% endfor %}
{% endif %}

但是前端输出的是空白的,content.type == "root" 没有进入判断。

阅读 728
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进