在页面模板 liquid (Shopify) 中显示来自 settings_data.json 的 JSON 数据数组
Display JSON data array from settings_data.json in page template liquid (Shopify)
我的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 liquid 模板页面中获取 header 部分变量?
我可以得到一个变量:
{% 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%"
}
}
},
但是,我无法获取和显示带有变量的数组。
请帮忙。
假设您的 JSONOBJ 是正确的。
var JSONOBJ={
"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"
}
}}}}
console.log(JSONOBJ.current.sections.header.settings.message_text)
settings_data.json 文件不是您可以在 Liquid 中直接访问的文件 - 但您可以使用适当的 Liquid 命令访问存储在其中的值。
Liquid 中的全局 settings
object 使您可以访问 settings_schema.json
文件中定义的所有变量,仅此而已。
但是,您的 color_text
设置不是主题设置,它是名为 'header' 的部分的部分设置。这个变量可以作为 section.settings.color_text
访问,只要您从 header 部分内部调用它即可。
块设置以类似的方式访问。假设您有某种 for block in section.blocks
循环,这些 block-level 设置可以作为 block.settings.whatever_key_you_made
访问
记住 - 您创建的所有设置都有相应的范围,需要适当访问! settings_schema.json
给你你的全局 settings
object;每个部分都有其私有 settings
object;每个区块都有自己的个人 settings
object.
希望对您有所帮助!
我的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 liquid 模板页面中获取 header 部分变量?
我可以得到一个变量:
{% 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%"
}
}
},
但是,我无法获取和显示带有变量的数组。
请帮忙。
假设您的 JSONOBJ 是正确的。
var JSONOBJ={
"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"
}
}}}}
console.log(JSONOBJ.current.sections.header.settings.message_text)
settings_data.json 文件不是您可以在 Liquid 中直接访问的文件 - 但您可以使用适当的 Liquid 命令访问存储在其中的值。
Liquid 中的全局 settings
object 使您可以访问 settings_schema.json
文件中定义的所有变量,仅此而已。
但是,您的 color_text
设置不是主题设置,它是名为 'header' 的部分的部分设置。这个变量可以作为 section.settings.color_text
访问,只要您从 header 部分内部调用它即可。
块设置以类似的方式访问。假设您有某种 for block in section.blocks
循环,这些 block-level 设置可以作为 block.settings.whatever_key_you_made
记住 - 您创建的所有设置都有相应的范围,需要适当访问! settings_schema.json
给你你的全局 settings
object;每个部分都有其私有 settings
object;每个区块都有自己的个人 settings
object.
希望对您有所帮助!