arrays - 在页面模板液体(Shopify)中显示来自 settings_data.json 的 JSON 数据数组
问题描述
我的 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%"
}
}
},
但是,我无法获取并显示带有变量的数组。
请帮忙。
解决方案
settings_data.json 文件不是您可以在 Liquid 中直接访问的文件 - 但您可以使用适当的 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
物品。
希望这可以帮助!
推荐阅读
- java - Android:缩放两个视图
- prestashop - 覆盖 searchProvider.php 不起作用
- hash - Redis,按哈希查找,按字段值查找
- javascript - 如何将 setState 值插入 useEffect 挂钩?
- python - 根据用户要求的Python密码生成器问题
- html - 是什么导致我的 Angular 模板中出现此错误消息:E 解析模板中的错误:意外的结束标记“div”
- vim - 是否可以使用 Vim Tagbar 插件扩大标签搜索的范围?
- excel - 需要一个更整洁的解决方案
- javascript - 消除数据点之间的差距
- laravel - zsh:找不到命令:laravel