首页 > 解决方案 > 在页面模板液体(Shopify)中显示来自 settings_data.json 的 JSON 数据数组

问题描述

我的 setting_data.json(Deput Shopify 主题)文件:

{
  "current": {
    "checkout_error_color": "#ff6d6d",
    "sections": {
      "header": {
        "type": "header",
        "settings": {
          "align_logo": "left",
          "logo": "shopify:\/\/shop_images\/logo_9bb43dd5-21d6-442c-8a19-0f4adf03e13a.png",
          "logo_max_width": 100,
          "main_linklist": "main-menu",
          "message": true,
          "home_page_only": true,
          "message_text": "Paw Paper – Edible Gift Wrap for Pets",
          "message_link": "",
          "color_bg": "#162950",
          "color_text": "#ffffff"
        }
      },

如何在 Shopify 液体模板页面中获取部分标题变量?

我可以得到一个变量:

{% assign text_color = settings.color_text %}
{{ text_color }}

我需要在页面上显示自定义块并从 settings_data.json 获取数据

"1543393771012": {
        "type": "custom-content",
        "blocks": {
          "1543393771012-1": {
            "type": "image",
            "settings": {
              "image": "shopify:\/\/shop_images\/info.png",
              "width": "50%",
              "alignment": "center"
            }
          },
          "1543393802354": {
            "type": "html",
            "settings": {
              "code": "<p>Paw Paper is the world's first edible wrapping paper designed specifically for pets. Our edible paper is 100% all-natural, made from potato starch with Omega-3 enhanced beef flavoring. It's water-soluble so no tape required!<\/p> <p>Just lick it like a stamp or dab water on the edges to bind the seams.<\/p>",
              "width": "50%"
            }
          }
        },

但是,我无法获取并显示带有变量的数组。

请帮忙。

标签: arraysjsonshopifyliquid

解决方案


settings_data.json 文件不是您可以在 Liquid 中直接访问的文件 - 但您可以使用适当的 Liquid 命令访问其中存储的值。

Liquid 中的全局settings对象使您可以访问settings_schema.json文件中定义的所有变量,仅此而已。

但是,您的color_text设置不是主题设置,而是名为“标题”的部分的部分设置。section.settings.color_text只要您从标题部分中调用该变量,就可以访问该变量。

以类似的方式访问块设置。假设您有某种for block in section.blocks循环,这些块级设置可以访问为block.settings.whatever_key_you_made

请记住 - 您创建的所有设置都有相应的范围,需要适当地访问! settings_schema.json给你你的全局settings对象;每个部分都有其私有settings对象;每个街区都有自己的个人settings物品。

希望这可以帮助!


推荐阅读