Shopify二次开发之五:元字段(Metafields)

目录

解释

操作

1、添加Custom data

2、选择特定类型的数据

3、为Page配置元子段和值

4、模板访问


解释

Shopify Metafields 是一种用于存储和管理自定义数据的功能。它们允许商户在商城中的产品、订单、客户、Page等对象上添加自定义字段,以满足特定业务需求。

操作

1、添加Custom data

可以为Products、Pages添加自定义数据,比如选择了Pages,那么在任何Page模板下配置了metafield的值,可以用page.metafields.namespace.key.value访问添加的特定类型的元字段内容,又比如选择了Products,那么在product模板下,可以用product.metafields.namespace.key.value访问为产品添加的特定数据的元字段内容,Collections同上,其它的比如Orders也有特定的用法。

就拿pages做举例

2、选择特定类型的数据

为Pages添加自定义内容的数据type,可以有普通数据type:文本、日期、布尔、json、整数等,也可以有引用数据type:product、file、collection、page等。

3、为Page配置元子段和值

选择一个页面

show all

配置元字段值

4、模板访问

在page.xxx.json,通过.value访问元字段内容

基本元子段type

typeliquid codevalue
Single line text{{ page.metafields.custom.single_line_text.value }}single line text aaaaa
Single line text (List){{ page.metafields.custom.list_single_line_text.value }}

some radom text1

some radom text2

some radom text3

integer{{ page.metafields.custom.integer.value }}10
true of false{{ page.metafields.custom.boolean.value }}true
json{{ page.metafields.custom.json.value }} {"name"=>"sa"}
date{{ page.metafields.custom.date.value }}2023-12-06
money{{ page.metafields.custom.money.value }}2300
Multi-line text {{ page.metafields.custom.multi_line_text.value }}line text 1 line text 2 line text 3

循环Single line text (List)

{% assign list_line_text = page.metafields.custom.list_single_line_text.value %}
{% for line_text in list_line_text %}{{ line_text }}{% endfor %}
引用元子段type
typeliquid codevalue
product{{ page.metafields.custom.product.value }}ProductDrop
list product{{ page.metafields.custom.list_product.value }}ProductListDrop
collection{{ page.metafields.custom.collection.value }}CollectionDrop
metaobjects{{ page.metafields.custom.metaobjects.value }}MetaobjectDrop
file{{ page.metafields.custom.file.value }} files/app-screen-3.png

访问product

{% assign product_value = page.metafields.custom.product.value %}
{{ product_value.title }}
{{ product_value.price | money}}
{{ product_value.featured_image | image_url: width: 100 | image_tag }}
{{ product_value.url | link_to: product_value.url }}

访问list product

{% assign list_product = page.metafields.custom.list_product.value %}
{% for product_item in list_product %}
    {{ product_item.title }}
    {{ product_item.featured_image | image_url: width: 100 | image_tag }}
    {{ product_item.price | money }}
    {{ product_item.url | link_to: product_item.url }}
{% endfor %}

访问collection

{% assign collection_value = page.metafields.custom.collection.value %}
{{ collection_value.title }}
{{ collection_value.url | link_to: collection.url }}

访问metaobjects

{% assign metaObject = page.metafields.custom.metaobjects.value %}
{{ metaObject.name }}
{{ metaObject.gender }}

访问file

{% assign file = page.metafields.custom.file.value %}
{{ file | image_url: width: 100 | image_tag }}

5、内嵌式app管理元字段

Metafields Guru

  • 14
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值