跳到主要内容

格式过滤器

Format filters 将特定格式应用于特定数据类型。

date

string | date: string
returns  string

将时间戳转换为另一种日期格式。

date filter 接受与 PHP strftime 方法相同的日期格式化参数。有关格式缩写列表,请参阅 PHP 文档

{{ '2023-06-15 15:11:02' | date: '%B %d, %Y' }}
June 15, 2023

当前日期

您可以将 date filter 应用于关键字 'now''today' 以输出当前时间戳。

📘 注意

时间戳将反映 Liquid 最后一次渲染时的时间。因此,根据上下文和缓存情况,时间戳可能不会在每次页面访问时更新。

{{ 'now' | date: '%B %d, %Y %H:%M:%S' }}
June 15, 2023 15:23:57

未来或过去的日期

您可以应用与 PHP strtotime 方法相同的参数来输出任何英文文本日期。

{{ '+7 day' | date: '%B %d, %Y' }}
June 22, 2023

格式化 Unix 时间戳

您可以将 date filter 应用于关键字 r 以格式化 Unix 时间戳。

{{ 'now' | date: 'r' }}
Thu, 15 Jun 2023 15:32:06 +0800

json

variable | join
returns  string

将字符串或 object 转换为 JSON 格式。

📘 提示

在 JavaScript 中使用 JSON 输出时,无需用引号包裹,因为 json filter 已包含引号。json filter 还会对输出中的引号进行转义。

{{ product | json }}
{
"id": "0f0eaab1-afaa-4bf2-b1d9-993f10c2c63e",
"title": "Lace-up Leather Manston Runner",
"brief": "",
"description": "<p>Sporty yet sophisticated, this short-sleeve ribbed crewneck is made from super-fine Egyptian cotton with stretch that hugs in all the right places. Finished with varsity stripe detail on the cuff and hem.<br /><br />55% linen, 45% cotton<br />oversized relax fit <br />cotton herringbone drawcord<br />cold delicate machine wash<br />Model is 177cm, wearing size S.<br /><br />This is a demo store. You can purchase products like this from <a href=\"https://www.rag-bone.com\" target=\"_blank\" rel=\"noopener noreferrer\">rag&amp;bone</a>.</p>",
"vendor": "Nero",
"vendor_url": "",
"has_only_default_variant": false,
"requires_shipping": true,
"taxable": false,
"inventory_policy": "deny",
"inventory_quantity": 540,
"inventory_tracking": true,
"published": true,
"handle": "lace-up-leather-manston-runner",
"spu": "",
"note": "",
"need_variant_image": false,
"fake_sales": 0,
"display_fake_sales": false,
"independent_seo": false,
"updated_at": "2023-06-19T01:11:44Z",
"created_at": "2021-08-23T01:24:46Z",
"mixed_wholesale": false,
"product_type": "",
"tags": "Color_Black,Color_Crimson,Color_Indianred,Location_Louisiana,Price_$300-$400",
"available": true,
"price_min": "325",
"price": "325",
"price_max": "358",
"compare_at_price_min": "0",
"compare_at_price": "0",
"compare_at_price_max": "388",
"retail_price_min": "0",
"retail_price_max": "388",
"url": "/products/lace-up-leather-manston-runner",
"published_at": "2021-10-21T06:51:30Z",
"sales": 0,
"image": {
"src": "//cdn.shoplazza.com/5afeee913a4f8ff183295949f8e9d129.jpeg",
"path": "5afeee913a4f8ff183295949f8e9d129.jpeg",
"width": 1280,
"height": 1710,
"alt": "",
"aspect_ratio": 0.7485380116959064
},
"meta_title": "Lace-up Leather Manston Runner",
"meta_description": "Sporty yet sophisticated, this short-sleeve ribbed crewneck is made from super-fine Egyptian cotton with stretch that hugs in all the right places. Finished with varsity stripe detail on the cuff and hem.<br><br>55% linen, 45% cotton<br>oversized relax fit <br>cotton herringbone drawcord<br>cold delicate machine wash<br>Model is 177cm, wearing size S.<br><br>This is a demo store. You can purchase products like this from <a href=\"https://www.rag-bone.com\" target=\"_blank\" rel=\"noopener noreferrer\">rag&amp;bone</a>.",
"meta_keyword": "",
"options": [
{
"id": "6747f563-d35e-43da-9c16-1de70478f07e",
"name": "Color",
"position": 1,
"values": [
"DarkRed"
]
},
{
"id": "8f2584b4-3ded-4820-b060-403b81f1150f",
"name": "Size",
"position": 2,
"values": [
"35",
"36",
"37",
"38",
"39",
"40"
]
}
],
"variants": [
{
"id": "d7e63bd8-d066-4ba0-9c4f-e206bba7bc59",
"product_id": "0f0eaab1-afaa-4bf2-b1d9-993f10c2c63e",
"title": "DarkRed-35",
"weight_unit": "g",
"inventory_quantity": 90,
"sku": "WFF19FF0321D32-1",
"barcode": "",
"position": 1,
"option1": "DarkRed",
"option2": "35",
"option3": "",
"note": "",
"image": null,
"wholesale_price": [
{
"price": 358,
"min_quantity": 1
}
],
"weight": "568",
"compare_at_price": "388",
"price": "358",
"retail_price": "388",
"available": true,
"url": "/products/lace-up-leather-manston-runner?variant=d7e63bd8-d066-4ba0-9c4f-e206bba7bc59",
"available_quantity": 90,
"options": [
{
"name": "Color",
"value": "DarkRed"
},
{
"name": "Size",
"value": "35"
}
],
"off_ratio": 8,
"flashsale_info": [],
"sales": 0
},
{
"id": "12309f3f-71db-4e32-b564-1ff647bb43a7",
"product_id": "0f0eaab1-afaa-4bf2-b1d9-993f10c2c63e",
"title": "DarkRed-36",
"weight_unit": "kg",
"inventory_quantity": 90,
"sku": "WFF19FF0321D32-2",
"barcode": "",
"position": 2,
"option1": "DarkRed",
"option2": "36",
"option3": "",
"note": "",
"image": null,
"wholesale_price": [
{
"price": 325,
"min_quantity": 1
}
],
"weight": "0",
"compare_at_price": "0",
"price": "325",
"retail_price": "0",
"available": true,
"url": "/products/lace-up-leather-manston-runner?variant=12309f3f-71db-4e32-b564-1ff647bb43a7",
"available_quantity": 90,
"options": [
{
"name": "Color",
"value": "DarkRed"
},
{
"name": "Size",
"value": "36"
}
],
"off_ratio": 0,
"flashsale_info": [],
"sales": 0
},
{
"id": "1f5b0e25-50e1-4196-9bee-25d825cd3ca9",
"product_id": "0f0eaab1-afaa-4bf2-b1d9-993f10c2c63e",
"title": "DarkRed-37",
"weight_unit": "kg",
"inventory_quantity": 90,
"sku": "WFF19FF0321D32-3",
"barcode": "",
"position": 3,
"option1": "DarkRed",
"option2": "37",
"option3": "",
"note": "",
"image": null,
"wholesale_price": [
{
"price": 325,
"min_quantity": 1
}
],
"weight": "0",
"compare_at_price": "0",
"price": "325",
"retail_price": "0",
"available": true,
"url": "/products/lace-up-leather-manston-runner?variant=1f5b0e25-50e1-4196-9bee-25d825cd3ca9",
"available_quantity": 90,
"options": [
{
"name": "Color",
"value": "DarkRed"
},
{
"name": "Size",
"value": "37"
}
],
"off_ratio": 0,
"flashsale_info": [],
"sales": 0
},
{
"id": "b11e6ff8-b8ed-4b4c-a531-dbd8c923d813",
"product_id": "0f0eaab1-afaa-4bf2-b1d9-993f10c2c63e",
"title": "DarkRed-38",
"weight_unit": "kg",
"inventory_quantity": 90,
"sku": "WFF19FF0321D32-4",
"barcode": "",
"position": 4,
"option1": "DarkRed",
"option2": "38",
"option3": "",
"note": "",
"image": null,
"wholesale_price": [
{
"price": 325,
"min_quantity": 1
}
],
"weight": "0",
"compare_at_price": "0",
"price": "325",
"retail_price": "0",
"available": true,
"url": "/products/lace-up-leather-manston-runner?variant=b11e6ff8-b8ed-4b4c-a531-dbd8c923d813",
"available_quantity": 90,
"options": [
{
"name": "Color",
"value": "DarkRed"
},
{
"name": "Size",
"value": "38"
}
],
"off_ratio": 0,
"flashsale_info": [],
"sales": 0
},
{
"id": "5e1e5f57-93eb-4909-a696-2516aa25cb44",
"product_id": "0f0eaab1-afaa-4bf2-b1d9-993f10c2c63e",
"title": "DarkRed-39",
"weight_unit": "kg",
"inventory_quantity": 90,
"sku": "WFF19FF0321D32-5",
"barcode": "",
"position": 5,
"option1": "DarkRed",
"option2": "39",
"option3": "",
"note": "",
"image": null,
"wholesale_price": [
{
"price": 325,
"min_quantity": 1
}
],
"weight": "0",
"compare_at_price": "0",
"price": "325",
"retail_price": "0",
"available": true,
"url": "/products/lace-up-leather-manston-runner?variant=5e1e5f57-93eb-4909-a696-2516aa25cb44",
"available_quantity": 90,
"options": [
{
"name": "Color",
"value": "DarkRed"
},
{
"name": "Size",
"value": "39"
}
],
"off_ratio": 0,
"flashsale_info": [],
"sales": 0
},
{
"id": "bc0cb233-e393-478f-8c44-a652a30bfafb",
"product_id": "0f0eaab1-afaa-4bf2-b1d9-993f10c2c63e",
"title": "DarkRed-40",
"weight_unit": "kg",
"inventory_quantity": 90,
"sku": "WFF19FF0321D32-6",
"barcode": "",
"position": 6,
"option1": "DarkRed",
"option2": "40",
"option3": "",
"note": "",
"image": null,
"wholesale_price": [
{
"price": 325,
"min_quantity": 1
}
],
"weight": "0",
"compare_at_price": "0",
"price": "325",
"retail_price": "0",
"available": true,
"url": "/products/lace-up-leather-manston-runner?variant=bc0cb233-e393-478f-8c44-a652a30bfafb",
"available_quantity": 90,
"options": [
{
"name": "Color",
"value": "DarkRed"
},
{
"name": "Size",
"value": "40"
}
],
"off_ratio": 0,
"flashsale_info": [],
"sales": 0
}
],
"images": [
{
"src": "//cdn.shoplazza.com/5afeee913a4f8ff183295949f8e9d129.jpeg",
"path": "5afeee913a4f8ff183295949f8e9d129.jpeg",
"width": 1280,
"height": 1710,
"alt": "",
"aspect_ratio": 0.7485380116959064
},
{
"src": "//cdn.shoplazza.com/44cf329e8f4ebe6a2b4b9cc29674c181.jpeg",
"path": "44cf329e8f4ebe6a2b4b9cc29674c181.jpeg",
"width": 1280,
"height": 1710,
"alt": "",
"aspect_ratio": 0.7485380116959064
},
{
"src": "//cdn.shoplazza.com/f4d670f4175e188a3cb9b0449f0ca00d.jpeg",
"path": "f4d670f4175e188a3cb9b0449f0ca00d.jpeg",
"width": 1280,
"height": 1710,
"alt": "",
"aspect_ratio": 0.7485380116959064
},
{
"src": "//cdn.shoplazza.com/c2ff6094baab824afde797a364384813.jpeg",
"path": "c2ff6094baab824afde797a364384813.jpeg",
"width": 1280,
"height": 1710,
"alt": "",
"aspect_ratio": 0.7485380116959064
},
{
"src": "//cdn.shoplazza.com/9ca7f7e1857fd33df730497b9407bd6d.jpeg",
"path": "9ca7f7e1857fd33df730497b9407bd6d.jpeg",
"width": 1280,
"height": 1710,
"alt": "",
"aspect_ratio": 0.7485380116959064
},
{
"src": "//cdn.shoplazza.com/7b4061544a337676e02e97d0bdc7b468.jpeg",
"path": "7b4061544a337676e02e97d0bdc7b468.jpeg",
"width": 1280,
"height": 1710,
"alt": "",
"aspect_ratio": 0.7485380116959064
},
{
"src": "//cdn.shoplazza.com/48a60cb49a67a5677e258211b4b03be0.jpeg",
"path": "48a60cb49a67a5677e258211b4b03be0.jpeg",
"width": 1280,
"height": 1710,
"alt": "",
"aspect_ratio": 0.7485380116959064
}
],
"redirect": false,
"redirect_url": "",
"retail_price": "0",
"price_varies": false,
"off_ratio": 0,
"flashsale_info": []
}

Exclude specific properties

variable | join: string
returns  string

You can specify a comma-separated string to indicate the content of the property that does not contain.

{{ product | json: 'variants,options,images' }}
{
"id": "0f0eaab1-afaa-4bf2-b1d9-993f10c2c63e",
"title": "Lace-up Leather Manston Runner",
"brief": "",
"description": "Sporty yet sophisticated, this short-sleeve ribbed crewneck is made from super-fine Egyptian cotton with stretch that hugs in all the right places. Finished with varsity stripe detail on the cuff and hem. 55% linen, 45% cotton oversized relax fit cotton herringbone drawcord cold delicate machine wash Model is 177cm, wearing size S. This is a demo store. You can purchase products like this from rag&bone<\/a>.",
"vendor": "Nero",
"vendor_url": "",
"has_only_default_variant": false,
"requires_shipping": true,
"taxable": false,
"inventory_policy": "deny",
"inventory_quantity": 540,
"inventory_tracking": true,
"published": true,
"handle": "lace-up-leather-manston-runner",
"spu": "",
"note": "",
"need_variant_image": false,
"fake_sales": 0,
"display_fake_sales": false,
"independent_seo": false,
"updated_at": "2021-10-21T06:51:30Z",
"created_at": "2021-08-23T01:24:46Z",
"mixed_wholesale": false,
"tags": "Color_Black,Color_Crimson,Color_Indianred,Location_Louisiana,Price_$300-$400",
"available": true,
"price_min": "325",
"price": "325",
"price_max": "325",
"compare_at_price_min": "0",
"compare_at_price": "0",
"compare_at_price_max": "0",
"retail_price_min": "0",
"retail_price_max": "0",
"url": "\/products\/lace-up-leather-manston-runner",
"published_at": "2021-10-21T06:51:30Z",
"sales": 0,
"image": {
"src": "\/\/img.staticdj.com\/5afeee913a4f8ff183295949f8e9d129.jpeg",
"path": "5afeee913a4f8ff183295949f8e9d129.jpeg",
"width": 1280,
"height": 1710,
"alt": "",
"aspect_ratio": 0.7485380116959064
},
"meta_title": "Lace-up Leather Manston Runner",
"meta_description": "Sporty yet sophisticated, this short-sleeve ribbed crewneck is made from super-fine Egyptian cotton with stretch that hugs in all the right places. Finished with varsity stripe detail on the cuff and hem. 55% linen, 45% cotton oversized relax fit cotton herringbone drawcord cold delicate machine wash Model is 177cm, wearing size S. This is a demo store. You can purchase products like this from rag&bone<\/a>.",
"meta_keyword": "",
"redirect": false,
"redirect_url": "",
"retail_price": "0",
"price_varies": true,
"off_ratio": 0,
"flashsale_info": []
}

weight_with_unit

number | weight_with_unit
returns  string

variant object 生成格式化的重量。重量单位在 Shoplazza 管理后台的常规设置中配置。

{% assign variant = product.variants | first %}

{{ variant.weight | weight_with_unit }}
{
"product": {
"variants": [
{
"weight": 228
},
{
"weight": 256
},
{
"weight": 242
},
{
"weight": 200
}
]
}
}
228 kg

Override the default unit

number | weight_with_unit: variable
returns  string

You can specify a unit to override the default from the general settings.

{% assign variant = product.variants | first %}

{{ variant.weight | weight_with_unit: 'g' }}
{
"product": {
"variants": [
{
"weight": 228
},
{
"weight": 256
},
{
"weight": 242
},
{
"weight": 200
}
]
}
}
228 g