json 在Shopify中,根据模板中的window.location.hostname启用/禁用某个部分或部分,

g6ll5ycj  于 2023-10-21  发布在  其他
关注(0)|答案(1)|浏览(156)

不确定这是否可能?对这一切都很陌生。但这是我想做的:“collapsible_row-4”只需要在我们的.fr和.it域访问此页面时,所以我想只在这些页面上启用它-我试图根据window.location.hostname == our .fr形成某种if/else语句||.it域名,但我似乎无法让它工作?任何帮助将不胜感激!(我已经附上了整个.json文件以及它在本节中调用的可折叠内容的.liquid)部分:

"2cbaf563-3af7-4130-8215-7565a7511b86": {
"type": "collapsible-content-2",
"blocks": {
"template--19225607635265__2cbaf563-3af7-4130-8215-7565a7511b86-collapsible_row-1": {
"type": "collapsible_row",
"settings": {
"heading": "Details",
"icon": "check_mark",
"row_content": "",
"liquid": "{{ product.metafields.custom.details_tab_content }}",
"page": ""
}
},
"template--19225607635265__2cbaf563-3af7-4130-8215-7565a7511b86-collapsible_row-2": {
"type": "collapsible_row",
"settings": {
"heading": "Technical Specs",
"icon": "check_mark",
"row_content": "",
"liquid": "

\n <tr class="row1">\n <td class="col1">\n Weight\n </td>\n <td class="col2">\n {{ product.metafields.custom.weight }} \n </td>\n </tr><tr class="row2">\n <td class="col1">\n Dimensions\n </td>\n <td class="col2">\n {{ product.metafields.custom.dimensions }} \n </td>\n </tr>\n</table>",
"page": ""
}
},
"template--19225607635265__2cbaf563-3af7-4130-8215-7565a7511b86-collapsible_row-3": {
"type": "collapsible_row",
"settings": {
"heading": "Warranty",
"icon": "check_mark",
"row_content": "
{{ product.metafields.custom.warranty_tab_content | metafield_tag }}</p>",
"liquid": "",
"page": ""
}
},
"template--19225607635265__2cbaf563-3af7-4130-8215-7565a7511b86-collapsible_row-4": {
"type": "collapsible_row",
"settings": {
"heading": "Package Recycling",
"icon": "check_mark",
"row_content": "",
"liquid": "<script id='buyerdock-api' data-api='5eU73ihMKY1695729119lRLAIZ' data-product='{{ product.metafields.custom.buyerdock_widget }}' src='https:\/\/buyerdock.com\/buyerdock_api\/api_response.js'></script>",
"page": ""
}
}
},
"block_order": [
"template--19225607635265__2cbaf563-3af7-4130-8215-7565a7511b86-collapsible_row-1",
"template--19225607635265__2cbaf563-3af7-4130-8215-7565a7511b86-collapsible_row-2",
"template--19225607635265__2cbaf563-3af7-4130-8215-7565a7511b86-collapsible_row-3",
"template--19225607635265__2cbaf563-3af7-4130-8215-7565a7511b86-collapsible_row-4"
],

整个文件

{
  "sections": {
    "main": {
      "type": "main-product",
      "blocks": {
        "vendor": {
          "type": "text",
          "settings": {
            "text": "{{ product.vendor }}",
            "text_style": "uppercase"
          }
        },
        "title": {
          "type": "title",
          "settings": {
          }
        },
        "caption": {
          "type": "text",
          "settings": {
            "text": "{{ product.metafields.descriptors.subtitle.value }}",
            "text_style": "subtitle"
          }
        },
        "price": {
          "type": "price",
          "settings": {
          }
        },
        "variant_picker": {
          "type": "variant_picker",
          "settings": {
            "picker_type": "dropdown"
          }
        },
        "quantity_selector": {
          "type": "quantity_selector",
          "settings": {
          }
        },
        "buy_buttons": {
          "type": "buy_buttons",
          "settings": {
            "show_dynamic_checkout": false
          }
        },
        "description": {
          "type": "description",
          "disabled": true,
          "settings": {
          }
        },
        "collapsible-row-0": {
          "type": "collapsible_tab",
          "disabled": true,
          "settings": {
            "heading": "Materials",
            "icon": "leather",
            "content": "",
            "liquid": "",
            "page": ""
          }
        },
        "collapsible-row-1": {
          "type": "collapsible_tab",
          "disabled": true,
          "settings": {
            "heading": "Shipping & Returns",
            "icon": "truck",
            "content": "",
            "liquid": "",
            "page": ""
          }
        },
        "collapsible-row-2": {
          "type": "collapsible_tab",
          "disabled": true,
          "settings": {
            "heading": "Dimensions",
            "icon": "ruler",
            "content": "",
            "liquid": "",
            "page": ""
          }
        },
        "collapsible-row-3": {
          "type": "collapsible_tab",
          "disabled": true,
          "settings": {
            "heading": "Care Instructions",
            "icon": "heart",
            "content": "",
            "liquid": "",
            "page": ""
          }
        },
        "share": {
          "type": "share",
          "disabled": true,
          "settings": {
            "share_label": "Share"
          }
        }
      },
      "block_order": [
        "vendor",
        "title",
        "caption",
        "price",
        "variant_picker",
        "quantity_selector",
        "buy_buttons",
        "description",
        "collapsible-row-0",
        "collapsible-row-1",
        "collapsible-row-2",
        "collapsible-row-3",
        "share"
      ],
      "settings": {
        "enable_sticky_info": true,
        "gallery_layout": "thumbnail",
        "media_size": "large",
        "mobile_thumbnails": "hide",
        "hide_variants": true,
        "enable_video_looping": false
      }
    },
    "image-with-text": {
      "type": "image-with-text",
      "blocks": {
        "image-with-text-0": {
          "type": "heading",
          "settings": {
            "small_hide": false,
            "heading": "Flavour Profile",
            "heading_size": "h1"
          }
        },
        "image-with-text-1": {
          "type": "text",
          "settings": {
            "text": "<p>Pair text with an image to focus on your chosen product, collection, or blog post. Add details on availability, style, or even provide a review.<\/p>",
            "text_style": "body"
          }
        }
      },
      "block_order": [
        "image-with-text-0",
        "image-with-text-1"
      ],
      "disabled": true,
      "settings": {
        "full_width": false,
        "mobile_heading": "",
        "section_heading": "",
        "counter": "",
        "top": "",
        "bottom": "",
        "left": "",
        "right": "",
        "section_bg": "",
        "special_colors": "",
        "text_colors": "",
        "height": "small",
        "desktop_image_width": "medium",
        "layout": "text_first",
        "desktop_content_position": "top",
        "desktop_content_alignment": "left",
        "content_layout": "no-overlap",
        "color_scheme": "background-2",
        "mobile_content_alignment": "left",
        "padding_top": 36,
        "padding_bottom": 36,
        "custom-class": ""
      }
    },
    "multicolumn": {
      "type": "multicolumn",
      "blocks": {
        "column-0": {
          "type": "column",
          "settings": {
            "title": "Free Shipping",
            "text": "<p>Pair text with an image to focus on your chosen product, collection, or blog post. Add details on availability, style, or even provide a review.<\/p>",
            "link_label": "",
            "link": ""
          }
        },
        "column-1": {
          "type": "column",
          "settings": {
            "title": "Hassle-Free Exchanges",
            "text": "<p>Pair text with an image to focus on your chosen product, collection, or blog post. Add details on availability, style, or even provide a review.<\/p>",
            "link_label": "",
            "link": ""
          }
        }
      },
      "block_order": [
        "column-0",
        "column-1"
      ],
      "disabled": true,
      "settings": {
        "title": "",
        "special_colors": "",
        "heading_size": "h1",
        "image_width": "full",
        "image_ratio": "adapt",
        "columns_desktop": 2,
        "column_alignment": "left",
        "background_style": "none",
        "button_label": "",
        "button_link": "",
        "color_scheme": "background-1",
        "columns_mobile": "1",
        "swipe_on_mobile": false,
        "padding_top": 36,
        "padding_bottom": 36
      }
    },
    "92c6625f-4006-4760-a37b-909c614f7fb2": {
      "type": "flavour-profile",
      "blocks": {
        "template--19225607635265__92c6625f-4006-4760-a37b-909c614f7fb2-heading-1": {
          "type": "heading",
          "settings": {
            "heading": "Flavour Profile",
            "sub-heading1": "",
            "sub-heading2": "",
            "sub-heading3": "",
            "heading_size": "h1"
          }
        },
        "template--19225607635265__92c6625f-4006-4760-a37b-909c614f7fb2-text-1": {
          "type": "text",
          "disabled": true,
          "settings": {
            "text": "<p>Pair text with an image to focus on your chosen product, collection, or blog post. Add details on availability, style, or even provide a review.<\/p>",
            "text_style": "body"
          }
        },
        "template--19225607635265__92c6625f-4006-4760-a37b-909c614f7fb2-button-1": {
          "type": "button",
          "disabled": true,
          "settings": {
            "button_label": "Button label",
            "button_link": ""
          }
        }
      },
      "block_order": [
        "template--19225607635265__92c6625f-4006-4760-a37b-909c614f7fb2-heading-1",
        "template--19225607635265__92c6625f-4006-4760-a37b-909c614f7fb2-text-1",
        "template--19225607635265__92c6625f-4006-4760-a37b-909c614f7fb2-button-1"
      ],
      "settings": {
        "image": "shopify:\/\/shop_images\/Generic-Bradley-Bisquette-e1580766145543_6d7419ad-4c1b-416f-9805-942c7c13a981.webp",
        "section_bg": "#121212",
        "special_colors": "#ce5c2f",
        "section_title": "",
        "height": "small",
        "desktop_image_width": "small",
        "layout": "image_first",
        "desktop_content_position": "top",
        "desktop_content_alignment": "left",
        "content_layout": "no-overlap",
        "color_scheme": "accent-1",
        "mobile_content_alignment": "left",
        "padding_top": 36,
        "padding_bottom": 36
      }
    },
    "2cbaf563-3af7-4130-8215-7565a7511b86": {
      "type": "collapsible-content-2",
      "blocks": {
        "template--19225607635265__2cbaf563-3af7-4130-8215-7565a7511b86-collapsible_row-1": {
          "type": "collapsible_row",
          "settings": {
            "heading": "Details",
            "icon": "check_mark",
            "row_content": "",
            "liquid": "{{ product.metafields.custom.details_tab_content }}",
            "page": ""
          }
        },
        "template--19225607635265__2cbaf563-3af7-4130-8215-7565a7511b86-collapsible_row-2": {
          "type": "collapsible_row",
          "settings": {
            "heading": "Technical Specs",
            "icon": "check_mark",
            "row_content": "",
            "liquid": "<table>\n  <tr class=\"row1\">\n    <td class=\"col1\">\n      Weight\n    <\/td>\n    <td class=\"col2\">\n     {{ product.metafields.custom.weight }} \n    <\/td>\n  <\/tr><tr class=\"row2\">\n    <td class=\"col1\">\n      Dimensions\n    <\/td>\n    <td class=\"col2\">\n     {{ product.metafields.custom.dimensions }} \n    <\/td>\n  <\/tr>\n<\/table>",
            "page": ""
          }
        },
        "template--19225607635265__2cbaf563-3af7-4130-8215-7565a7511b86-collapsible_row-3": {
          "type": "collapsible_row",
          "settings": {
            "heading": "Warranty",
            "icon": "check_mark",
            "row_content": "<p>{{ product.metafields.custom.warranty_tab_content | metafield_tag }}<\/p>",
            "liquid": "",
            "page": ""
          }
        },
        "template--19225607635265__2cbaf563-3af7-4130-8215-7565a7511b86-collapsible_row-4": {
          "type": "collapsible_row",
          "settings": {
            "heading": "Package Recycling",
            "icon": "check_mark",
            "row_content": "",
            "liquid": "<script id='buyerdock-api' data-api='5eU73ihMKY1695729119lRLAIZ' data-product='{{ product.metafields.custom.buyerdock_widget }}' src='https:\/\/buyerdock.com\/buyerdock_api\/api_response.js'><\/script>",
            "page": ""
          }
        }
      },
      "block_order": [
        "template--19225607635265__2cbaf563-3af7-4130-8215-7565a7511b86-collapsible_row-1",
        "template--19225607635265__2cbaf563-3af7-4130-8215-7565a7511b86-collapsible_row-2",
        "template--19225607635265__2cbaf563-3af7-4130-8215-7565a7511b86-collapsible_row-3",
        "template--19225607635265__2cbaf563-3af7-4130-8215-7565a7511b86-collapsible_row-4"
      ],
      "settings": {
        "caption": "",
        "section_bg": "",
        "heading": "Product Description",
        "heading_size": "h1",
        "heading_alignment": "left",
        "layout": "none",
        "color_scheme": "background-1",
        "container_color_scheme": "background-2",
        "open_first_collapsible_row": false,
        "image_ratio": "adapt",
        "desktop_layout": "image_second",
        "padding_top": 36,
        "padding_bottom": 36
      }
    },
    "product-recommendations": {
      "type": "product-recommendations",
      "settings": {
        "heading": "You may also like",
        "heading_size": "h2",
        "products_to_show": 4,
        "columns_desktop": 4,
        "color_scheme": "background-1",
        "image_ratio": "square",
        "show_secondary_image": true,
        "show_vendor": false,
        "show_rating": false,
        "columns_mobile": "2",
        "padding_top": 36,
        "padding_bottom": 28
      }
    },
    "88accd46-48e4-45b6-8143-d3891fc4dd89": {
      "type": "custom-liquid",
      "settings": {
        "section_bg": "",
        "custom_liquid": "\"<script id='buyerdock-api' data-api='5eU73ihMKY1695729119lRLAIZ' data-product='{{ product.metafields.custom.buyerdock_widget }}' src='https:\\\/\\\/buyerdock.com\\\/buyerdock_api\\\/api_response.js'><\\\/script>\"",
        "color_scheme": "inverse",
        "padding_top": 36,
        "padding_bottom": 36
      }
    }
  },
  "order": [
    "main",
    "image-with-text",
    "multicolumn",
    "92c6625f-4006-4760-a37b-909c614f7fb2",
    "2cbaf563-3af7-4130-8215-7565a7511b86",
    "product-recommendations",
    "88accd46-48e4-45b6-8143-d3891fc4dd89"
  ]
}

正如所提到的完全新的:我试着添加一个“disabled:“if语句沿着如下所示:“disabled:“{%- if window.location.hostname == 'www.bradleysmoker.fr'||“www.bradleysmoker.it”-%}假,{%- else -%}真,{%- endif -%},
我试着在“设置”下的行中的部分的顶部添加这个,并且在该部分中的第4行的实际子部分中,在设置下的行中。
我也尝试在页面顶部的第1行做类似的事情:第1行:{%- if window.location.hostname == 'www.bradleysmoker.fr'||'www.bradleysmoker.it' -%}最后一行之后的其余文件代码:{%- else -%}粘贴整个页面相同的代码,但没有额外的行,这是不需要从我们的其他域的其他访问者,最后一行后:{%- endif -%}

eiee3dmh

eiee3dmh1#

首先,您不能在.JSON文件中使用window.location.hostname(或任何JavaScript属性)和Liquid。
您要做的事情本质上是对包含这些块的部分进行一些修补。我可能需要更多的信息,但我认为你正在寻找的是请求对象,特别是'request.host'
你可以做什么:

  • 添加一个新的设置到块(复选框),将在所需的块上激活
  • 添加一个{%除非变量%}
  • 添加{% unless request.host contains '.fr' or request.host contains '.it' %} {% endif %}
  • 添加{% endunless %}

我希望这回答了你的问题,或者至少为你指出了一个方向。

相关问题