config-全局配置
模版装修页面,全局配置部分
关于全局配置
模版开发,需要有一些全局配置值,每个页面都需要用到,譬如:字体,logo,背景色等,那么就需要模版装修有一个全局配置,配置后,在模版文件里面直接使用配置值
1.全局配置模板,分为2个部分:
- 结构配置:配置schema部分,进行渲染配置的页面UI结构
- 配置值:将全局配置填写的值,进行保存存储
2.使用:结构定义好后,就可以在section模版卡片文件里面通过变量的方式调用
{{ setting.xxxx }}
模版装修,全局配置,配置值后,模版发布,该变量的值就是全局配置的值。
模版装修,全局配置
1.进入模版装修(必须是liquid的模版)后,点击左下角的全局配置,即可看到配置信息
2.右侧的装修部分的内容,是通过一个配置json来渲染的,也就是文件config/settings_schema.json
3.内容渲染后,用户界面操作,进行全局配置的编辑,然后进行模版发布,全局配置的值保存到文件:config/settings_data.json
通过这里我们可以了解到这2个文件的作用:
- 文件settings_schema.json:渲染模版装修的UI界面
- 文件settings_data.json:保存配置后的值
schema文件配置结构:settings_schema.json
1.打开文件config/settings_schema.json,可以看到里面的内容是一个json结构配置,是一个对象数组
1.1name是配置组
的名字:
- 默认是中文
- lang_params里面是多语言,en是英文,tw是繁体中文
{
"text": "通用设置",
"lang_params": {
"en": "General settings",
"tw": "通用設定"
}
}
1.2settings是这个配置组
的下面的详细配置信息
2.配置项
- settings是一个对象数组,每一个数组就是一个配置项
通过上图,可以看到配置json和界面UI显示内容的对应关系
配置说明:
type
:配置项的类型,譬如checkbox是开关类型id
:该配置项的id,必须唯一,是配置项的唯一标识,在data文件里面保存配置项的值,就是使用id作为值key,譬如:在scheme文件里面id的值是:use_favicon
,在data文件里面配置:"use_favicon":true
label
: 配置项的名称,支持多语言default
:配置项的默认值,也就是模版添加到店铺后,初始值info
: 备注说明,支持多语言
更多配置信息,参看:schema
data配置值:settings_data.json
打开文件:config/settings_schema.json 内容是一个json数组,current对应的是一个配置数组
{
"current": {
"use_favicon": false,
"type_base_size": 16,
"color_schemes": {
"default": {
"settings": {
"background": "rgba(255, 255, 255, 1)",
"background_secondary": "#f5f5f5",
"background_gradient": "",
"text": "#222222",
"subtext": "#666666",
"heading_text": "#222222",
"button": "#7DEF0A",
"button_label": "#ffffff",
"outline_button_label": "#000000",
"button_hover": "#222222",
"button_text_hover": "#ffffff",
"price_sale": "#e84e4e",
"price_regular": "#000000",
"form_field": "#ffffff",
"form_field_label": "#000000",
"tooltip": "#222222",
"tooltip_label": "#ffffff",
"border": "#eeeeee"
}
},
"dark": {
"settings": {
"background": "#000000",
"background_secondary": "#f5f5f5",
"background_gradient": "",
"text": "#ffffff",
"subtext": "#ffffff",
"heading_text": "#ffffff",
"button": "#ffffff",
"button_label": "#222222",
"outline_button_label": "#ffffff",
"button_hover": "#ffffff",
"button_text_hover": "#222222",
"price_sale": "#e84e4e",
"price_regular": "#ffffff",
"form_field": "#ffffff",
"form_field_label": "#222222",
"tooltip": "#ffffff",
"tooltip_label": "#222222",
"border": "#4b4b4b"
}
},
"footer": {
"settings": {
"background": "#f5f5f5",
"background_secondary": "#f5f5f5",
"background_gradient": "",
"text": "#000000",
"subtext": "#666666",
"heading_text": "#222222",
"button": "#222222",
"button_label": "#ffffff",
"outline_button_label": "#222222",
"button_hover": "#222222",
"button_text_hover": "#ffffff",
"price_sale": "#e84e4e",
"price_regular": "#000000",
"form_field": "#ffffff",
"form_field_label": "#000000",
"tooltip": "#222222",
"tooltip_label": "#ffffff",
"border": "#dedede"
}
},
"badge-hot": {
"settings": {
"background": "#9a84c8",
"background_secondary": "#f5f5f5",
"background_gradient": "",
"text": "#ffffff",
"subtext": "#ffffff",
"heading_text": "#F8F3F3",
"button": "#ffffff",
"button_label": "#222222",
"outline_button_label": "#ffffff",
"button_hover": "#ffffff",
"button_text_hover": "#222222",
"price_sale": "#ffffff",
"price_regular": "#ffffff",
"form_field": "#ffffff",
"form_field_label": "#000000",
"tooltip": "#ffffff",
"tooltip_label": "#222222",
"border": "#dedede"
}
},
"badge-new": {
"settings": {
"background": "#49a594",
"background_secondary": "#f5f5f5",
"background_gradient": "",
"text": "#ffffff",
"subtext": "#ffffff",
"heading_text": "#ffffff",
"button": "#ffffff",
"button_label": "#222222",
"outline_button_label": "#ffffff",
"button_hover": "#ffffff",
"button_text_hover": "#222222",
"price_sale": "#ffffff",
"price_regular": "#ffffff",
"form_field": "#ffffff",
"form_field_label": "#000000",
"tooltip": "#ffffff",
"tooltip_label": "#222222",
"border": "#dedede"
}
},
"badge-sale": {
"settings": {
"background": "#da3f3f",
"background_secondary": "#f5f5f5",
"background_gradient": "",
"text": "#ffffff",
"subtext": "#ffffff",
"heading_text": "#ffffff",
"button": "#ffffff",
"button_label": "#222222",
"outline_button_label": "#ffffff",
"button_hover": "#ffffff",
"button_text_hover": "#222222",
"price_sale": "#ffffff",
"price_regular": "#ffffff",
"form_field": "#ffffff",
"form_field_label": "#000000",
"tooltip": "#ffffff",
"tooltip_label": "#222222",
"border": "#dedede"
}
}
},
...
}
json对象
- 配置key,对应的是schema配置项的id
- 配置value,就是该配置对应的值,值可以是数字int,字符串string,也可以是对象等
实践
如果您想在全局配置里面,加入一个配置项,那么
1.在config/settings_schema.json加入一个配置
譬如:加入一个输入框,放到通用设置里面,如下图
然后点击右侧的保存按钮
2.进入模版装修,点击左下角的全局配置,在配置部分,就可以看到在schema里面加入的配置
可以打开或者关闭开关,然后点击发布,全局配置内容就保存了
3.打开文件:config/settings_data.json
将看到配置值:"my_custom_checkbox": true
4.在模版文件里面使用配置值
- 可以获取在模版装修,全局配置里面配置的值
{{ settings.my_custom_checkbox }}