My setting_data.json (Deput Shopify Theme)file:
{
"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"
}
},
How I can get section header variables in Shopify liquid template page?
I can get one variable:
{% assign text_color = settings.color_text %}
{{ text_color }}
I need to show custom block on page and get data for it from 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%"
}
}
},
But, I can not get and display array with variables.
Help, please.
答案 0 :(得分:1)
您不能直接在Liquid中访问settings_data.json文件,但是可以使用适当的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
对象。
希望这会有所帮助!
答案 1 :(得分:-1)
Assuming your JSONOBJ is correct.
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)