目錄
解釋
操作
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
type | liquid code | value |
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
type | liquid code | value |
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