shopify使用记录(未完待续....)

schema主题模块开发详解
https://help.shopify.com/en/themes/development/theme-editor/settings-schema#creating-from-scratch
liquid语法手册
https://liquid.bootcss.com/tags/iteration/

开发前要有一个好习惯呦

添加下面代码到settings中下次找文件的时候很方便

{
      "type": "text",
      "id": "private",
      "label": "程序参考字段默认勿动",
      "default": "product-page-text"
}
俺们常用的属性集合
"type": "text"    //输入框
"type": "checkbox"    //多选框
"type": "html"    //html代码块
"type": "image_picker"    //图片
"type": "textarea"    //文本域
"type": "richtext"    //富文本
"type": "collection" //选择产品分类
"type": "url"         //链接
模块开关
{% if section.settings.enable %}
	//把代码放到开关里然后在schema创建一个checkbox	.........
{% endif %}
块的使用
{%- for block in section.blocks -%}
    <div class="point-item">
        <img src="{{ block.settings.icon | img_url: '300x300' }}"/>
        <div class="point-content">
            <span>{{ block.settings.title | strip }}</span><br>
            {{ block.settings.infos | strip }}
        </div>
    </div>
{%- endfor -%}
/*-----------schema--------------*/
  "blocks": [
      {
        "type": "default",
        "name": "利益点",
        "settings": [
            {
                "id": "icon",
                "type": "image_picker",
                "label": "图标"
            },
              {
                "id": "title",
                "type": "text",
                "label": "标题"
            },            
            {
                "id": "infos",
                "type": "richtext",
                "label": "描述文字"
            }
        ]
      }
  ]
根据产品标签判断
{% assign productTags = product.tags | join:',' %}//声明一个变量productTags获取产品标签
{% if productTags contains 'photo-mistakes' %}//判断productTags是否包含我们后台创建的photo-mistakes标签
    …………
{% endif %}
根据产品sku判断
{% for block in section.blocks %} {% comment %}循环块{% endcomment %}
	{% include 'func-verify_rules', contain: block.settings.contain, detail: product %}{% comment %}引入判断sku的文件{% endcomment %}
	{% unless verify__rules_result == false %}    
		<div class="product-explain">{{ block.settings.txt }}</div>
    {% endunless %}
{% endfor %}
{% schema %}
    "blocks": [
        {
          "type": "text",
          "name": "添加集合",
          "settings": [
            {
              "type": "richtext",
              "id": "txt",
              "label": "添加文案"
            },
            {
              "type": "textarea",
              "id": "contain",
              "label": "显示规则",
              "info": "{\"handle\": \"a,b,c...\", \"sku\": \"C021,C022...\"}"
            }
          ]
        }  
    ]

{% endschema %}
块里多个section使用
{% for block in section.blocks %}
    {% case block.type %}
        {% when 'settings1' %}
             <div>{{ block.settings.title }}<div>
        {% when 'settings2' %}
             <div>{{ block.settings.txt }}<div>
    {% endcase %}
{% endfor %}

{% schema %}

"blocks": [
      {
        "type": "settings1",
        "name": "标题",
        "settings": [
            {
            "type": "text",
            "id": "title",
            "label": "这是一个标题"
            }
        ]
      },
      {
        "type": "settings2",
        "name": "内容",
        "settings": [
            {             
            "type": "text",
            "id": "txt ",
            "label": "这是内容"
            }
        ]
      }
    
]
{% endschema %}

判断页面是 首页 || collection || product || pages
{% comment %}判断 首页{% endcomment %}
{% if handle == blank %}
    …………
{% endif %}

{% comment %}判断 collection页面{% endcomment %}
{% if collection %}
    …………
{% endif %}

{% comment %}判断 product页面{% endcomment %}
{% if product %}
    …………
{% endif %}

{% comment %}判断 pages页面{% endcomment %}
{% if pages and handle != blank %}
    …………
{% endif %}
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值