📘 公式リファレンス🔧 リファレンス/フィルター初級
date フィルター(日付をフォーマット)
タイムスタンプを指定された形式に変換する。Ruby の strftime 記法に対応し、年月日を任意のフォーマットで表示できる。
用途
ブログ記事の公開日、注文日時、会員登録日をストアの言語・地域に合わせた見た目で表示するときに使う。
設置場所
Liquid テンプレート内で `{{ timestamp | date: '%B %d, %Y' }}` のように、タイムスタンプの直後にパイプ続きで記述する。
注意点
フォーマット文字列は Ruby の strftime 構文に従う必要があり、不正な書式を渡すとエラーになるため、公式ドキュメント(https://ruby-doc.org/core-3.1.1/Time.html#method-i-strftime)で %Y、%B などの指定子を確認する。`'now'` や `'today'` キーワードで現在時刻を出すこともできるが、キャッシュの影響で毎回更新されるとは限らない。テーマの locale ファイルで `date_formats` を定義すると、`format: 'custom_name'` で再利用可能な形式が作れる。
仕様
70 行 / json{
"category": "format",
"deprecated": false,
"deprecation_reason": "",
"description": "The `date` filter accepts the same parameters as Ruby's strftime method for formatting the date. For a list of shorthand\nformats, refer to the [Ruby documentation](https://ruby-doc.org/core-3.1.1/Time.html#method-i-strftime) or\n[strftime reference and sandbox](http://www.strfti.me/).",
"parameters": [
{
"description": "The desired date format.",
"name": "format",
"positional": false,
"required": false,
"types": [
"string"
]
}
],
"return_type": [
{
"type": "string",
"name": "",
"description": "",
"array_value": ""
}
],
"examples": [
{
"name": "",
"description": "",
"syntax": "",
"path": "/blogs/potion-notions/how-to-tell-if-you-have-run-out-of-invisibility-potion",
"raw_liquid": "{{ article.created_at | date: '%B %d, %Y' }}",
"parameter": false,
"display_type": "text",
"show_data_tab": true
},
{
"name": "The current date",
"description": "You can apply the `date` filter to the keywords `'now'` and `'today'` to output the current timestamp.\n\n> Note:\n> The timestamp will reflect the time that the Liquid was last rendered. Because of this, the timestamp might not be updated for every page view, depending on the context and caching.\n",
"syntax": "",
"path": "/",
"raw_liquid": "{{ 'now' | date: '%B %d, %Y' }}",
"parameter": false,
"display_type": "text",
"show_data_tab": true
},
{
"name": "format",
"description": "Specify a locale-aware date format. You can use the following formats:\n\n- `abbreviated_date`\n- `basic`\n- `date`\n- `date_at_time`\n- `default`\n- `on_date`\n- `short` (deprecated)\n- `long` (deprecated)\n\n> Note:\n> You can also [define custom formats](/docs/api/liquid/filters/date-setting-format-options-in-locale-files) in your theme's locale files.\n",
"syntax": "string | date: format: string",
"path": "/blogs/potion-notions/how-to-tell-if-you-have-run-out-of-invisibility-potion",
"raw_liquid": "{{ article.created_at | date: format: 'abbreviated_date' }}",
"parameter": true,
"display_type": "text",
"show_data_tab": true
},
{
"name": "Setting format options in locale files",
"description": "You can define custom date formats in your [theme's storefront locale files](/themes/architecture/locales/storefront-locale-files). These custom formats should be included in a `date_formats` category:\n\n```json\n\"date_formats\": {\n \"month_day_year\": \"%B %d, %Y\"\n}\n```\n",
"syntax": "",
"path": "/blogs/potion-notions/how-to-tell-if-you-have-run-out-of-invisibility-potion",
"raw_liquid": "{{ article.created_at | date: format: 'month_day_year' }}",
"parameter": true,
"display_type": "text",
"show_data_tab": true
}
],
"summary": "Converts a timestamp into another date format.",
"syntax": "string | date: string",
"name": "date"
}出典・ライセンス
- Repository:
- https://github.com/Shopify/theme-liquid-docs
- License:
- MIT
このコードは Shopify 著作の MIT ライセンスソースです。 原本の著作権は Shopify が保有します。日本語訳は ALSEL によるものです。
関連項目
📘 公式リファレンス🔧 リファレンス/フィルター初級
avatar フィルター(顧客アバター画像HTML生成)
顧客アバターが存在する場合、それを表示する HTML タグを生成するフィルター。customer オブジェクトに対して使用する。
📁 theme-liquid-docs·MIT·19 行
📘 公式リファレンス🔧 リファレンス/フィルター初級
default_errors フィルター(フォーム送信エラーを日本語化)
form.errors の各エラーコードに対応する既定のエラーメッセージを自動生成するフィルター。フォーム送信時の入力値不正や必須項目空白などのエラーを言語別に出力する。
📁 theme-liquid-docs·MIT·19 行
📘 公式リファレンス🔧 リファレンス/フィルター初級
date フィルター(日付を指定形式でフォーマット)
日付値を指定されたフォーマット文字列に従って整形する。フォーマット文字列が空の場合は元の値がそのまま返される。入力が日付に変換できない場合も元の値が返される。
📁 theme-liquid-docs·MIT·19 行
📘 公式リファレンス🔧 リファレンス/フィルター初級
payment_terms フィルター(Shop Pay分割払いバナーを生成)
product フォームまたは cart フォームに対して使用し、Shop Pay の分割払いオプションを表示するための HTML を生成するフィルター。顧客が購入時に分割払いプランを選択できるようにする。
📁 theme-liquid-docs·MIT·19 行
📘 公式リファレンス🔧 リファレンス/フィルター初級
abs フィルター(数値の絶対値を取得)
負の数を正の数に変換する。数値の絶対値(ゼロからの距離)を返すフィルター。
📁 theme-liquid-docs·MIT·30 行
📘 公式リファレンス🔧 リファレンス/フィルター初級
append フィルター(文字列の末尾に追加)
文字列の末尾に別の文字列を連結するフィルター。URL パスの結合やテキストの接尾辞追加に使う。
📁 theme-liquid-docs·MIT·30 行