settings_schema 在 Shopify 中——我如何获取数据?
settings_schema in Shopify — how do I get the data?
我从 settings_schema.json
创建了图像字段,id 为 header.png
。
后台出现上传栏,我上传了一张图片。但是我不知道如何访问该图像?
当我用 {{ settings | json }}
转储对象时,我看不到新上传的图像,或 json 文件(格式如下)中未预定义的任何数据.
我查阅了文档,但它没有告诉我数据何时不会出现在 settings
对象中。
我的settings_schema.json
:
[{
"name": "General",
"settings": [{
"type": "header",
"content": "Logo Options"
}, {
"type": "color",
"id": "bg_color",
"label": "Background (example)",
"default": "#ffffff"
}, {
"type": "color",
"id": "text_color",
"label": "Text color (example)",
"default": "#cccccc"
}, {
"type": "checkbox",
"id": "use_logo",
"label": "Use Custom Logo?"
}, {
"type": "image",
"id": "header.png",
"label": "Custom Logo",
"max-width": 940,
"max-height": 300
}, {
"type": "paragraph",
"content": "Maximum logo dimensions are 940px wide by 300px high.Your uploaded file will be resized to fit within those constraints.Need a full-width banner? Upload an image with a width of 940px, and a height of 300px or less."
}]
}]
您可以通过以下代码段像访问 /assets
文件夹中的常规图像一样访问图像:
{{ 'header.png' | asset_url }}
通过image字段上传的图片存储在主题的/assets
文件夹中,与settings_schema.json
文件中的字段id
同名。
它们不存在于 settings
对象中,因为它们的 id
是图像的文件名,而不是标识符。
PS: 你没有检查图片是否存在的能力。因此,如果需要,您将必须创建额外的复选框字段来创建 show/hide 功能。
我从 settings_schema.json
创建了图像字段,id 为 header.png
。
后台出现上传栏,我上传了一张图片。但是我不知道如何访问该图像?
当我用 {{ settings | json }}
转储对象时,我看不到新上传的图像,或 json 文件(格式如下)中未预定义的任何数据.
我查阅了文档,但它没有告诉我数据何时不会出现在 settings
对象中。
我的settings_schema.json
:
[{
"name": "General",
"settings": [{
"type": "header",
"content": "Logo Options"
}, {
"type": "color",
"id": "bg_color",
"label": "Background (example)",
"default": "#ffffff"
}, {
"type": "color",
"id": "text_color",
"label": "Text color (example)",
"default": "#cccccc"
}, {
"type": "checkbox",
"id": "use_logo",
"label": "Use Custom Logo?"
}, {
"type": "image",
"id": "header.png",
"label": "Custom Logo",
"max-width": 940,
"max-height": 300
}, {
"type": "paragraph",
"content": "Maximum logo dimensions are 940px wide by 300px high.Your uploaded file will be resized to fit within those constraints.Need a full-width banner? Upload an image with a width of 940px, and a height of 300px or less."
}]
}]
您可以通过以下代码段像访问 /assets
文件夹中的常规图像一样访问图像:
{{ 'header.png' | asset_url }}
通过image字段上传的图片存储在主题的/assets
文件夹中,与settings_schema.json
文件中的字段id
同名。
它们不存在于 settings
对象中,因为它们的 id
是图像的文件名,而不是标识符。
PS: 你没有检查图片是否存在的能力。因此,如果需要,您将必须创建额外的复选框字段来创建 show/hide 功能。