我的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%"
}
}
},但是,我无法获取和显示变量数组。
救命求你了。
发布于 2018-12-03 17:16:27
settings_data.json文件不是您可以直接在液体中访问的东西,但是您可以使用适当的液态命令访问存储在其中的值。
液态中的全局settings对象允许您访问settings_schema.json文件中定义的所有变量,仅此而已。
但是,您的color_text设置不是主题设置,而是名为“header”的部分设置。只要您在标头部分中调用该变量,就可以以section.settings.color_text的形式访问该变量。
以类似的方式访问块设置。假设您有某种for block in section.blocks循环,这些块级设置可以作为block.settings.whatever_key_you_made访问。
记住-您创建的所有设置都有相应的作用域,需要适当地访问!settings_schema.json为您提供全局settings对象;每个部分都有其私有的settings对象;每个块都有自己的个人settings对象。
希望这能有所帮助!
发布于 2018-12-03 13:17:56
假设你的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)
https://stackoverflow.com/questions/53594403
复制相似问题