跳到主要内容

Dynamic sources

包含在 Liquid template 中的 section 和 block 的设置,可以为商家提供连接一个或多个动态数据源的选项,具体取决于设置类型。

动态数据源可以是以下之一:

  • Metafield 值
  • 资源属性

📘 说明

动态数据源不适用于全局主题设置。

可用值

Shoplazza 根据以下条件确定每种可用动态数据源类型的值:

  • 该资源与 section 所在的 template 关联。
  • 当前设置上下文中的资源设置。

例如:

条件 描述
section 包含在 product template 与商品相关的 metafield 和属性将在以下位置可用:
  • section 的设置
  • section 中任何 block 的设置
section 包含 collection 类型设置 与专辑相关的 metafield 和属性将在以下位置可用:
  • section 的设置
  • section 中任何 block 的设置
section 的 block 包含 product 类型设置 该商品的 metafield 和属性将在该 block 的设置中可用。

下表列出了可用资源及其对应的属性:

资源 属性
product
  • title
  • vendor
collection
  • title
  • image

📘 说明

未来将会增加更多资源和资源属性。

下表概述了设置metafield 类型的兼容关系:

设置 Metafield
collection
  • collection_reference
color
  • color
image_picker
  • file_reference
page
  • page_reference
product
  • product_reference
richtext
  • single_line_text_field
  • multi_line_text_field
  • number_integer
  • number_decimal
  • date
  • date_time
  • weight
  • volume
  • dimension
  • rating
text
  • single_line_text_field
  • number_integer
  • number_decimal
  • date
  • date_time
  • weight
  • volume
  • dimension
  • rating
url
  • url

默认值

您可以将设置的默认值配置为引用动态数据源。但请仅在确保 section 或 block 的渲染上下文中动态数据源值存在时才这样做。例如,不要在以下 section 中使用与商品相关的值:

  • 该 section 可以在非 product template 中渲染。
  • 该 section 没有明确包含 product 类型设置来提供必要的值。

使用此方法时,额外的 Liquid 代码无效,因此您只能直接引用该值。如果包含额外的 Liquid,将会出现错误。

以下是引用动态数据源的 default 设置示例:

{
"type": "text",
"id": "featured_product_title",
"label": "Featured product title",
"default": "featuring: {{ product.title }}"
}