Liquid Snippets by ALSEL
📘 公式リファレンス🏷️ リファレンス/タグ初級

decrement タグ(変数を-1ずつ減少)

新しい変数を作成し、初期値を-1に設定して、呼び出すたびに1ずつ減少させる。increment タグと変数を共有するため、同じ変数に対して両方を使うと値が連動する。

用途
カウントダウンやループ内での逆順処理が必要なとき。例えば、商品リストで上から順に番号を減らしていく場合など。
設置場所
Liquid テンプレート内の任意の場所で `{% decrement 変数名 %}` と書く。layout、template、section ファイル内で宣言され、それに含まれるスニペット全体で共有される。
注意点
decrement で作成した変数は assign や capture で作成した変数と独立しており、同じ名前でも上書きされない。ただし、Liquid の定義済みオブジェクト(product、shop など)と同じ名前を付けると、そのオブジェクトにアクセスできなくなるため、変数名は慎重に選ぶ必要がある。increment タグとは変数を共有するため、同じ変数に対して両方を使うと値が連動する。
タグ:variabledecrementcounterloop

仕様

28 行 / json
{
  "category": "variable",
  "deprecated": false,
  "deprecation_reason": "",
  "description": "Variables that are declared with `decrement` are unique to the [layout](/themes/architecture/layouts), [template](/themes/architecture/templates),\nor [section](/themes/architecture/sections) file that they're created in. However, the variable is shared across\n[snippets](/themes/architecture/snippets) included in the file.\n\nSimilarly, variables that are created with `decrement` are independent from those created with [`assign`](/docs/api/liquid/tags/assign)\nand [`capture`](/docs/api/liquid/tags/capture). However, `decrement` and [`increment`](/docs/api/liquid/tags/increment) share\nvariables.",
  "parameters": [],
  "summary": "Creates a new variable, with a default value of -1, that's decreased by 1 with each subsequent call.\n\n> Caution:\n> Predefined Liquid objects can be overridden by variables with the same name.\n> To make sure that you can access all Liquid objects, make sure that your variable name doesn't match a predefined object's name.",
  "name": "decrement",
  "syntax": "{% decrement variable_name %}",
  "syntax_keywords": [
    {
      "keyword": "variable_name",
      "description": "The name of the variable being decremented."
    }
  ],
  "examples": [
    {
      "name": "",
      "description": "",
      "syntax": "",
      "path": "/",
      "raw_liquid": "{% decrement variable %}\n{% decrement variable %}\n{% decrement variable %}",
      "parameter": false,
      "display_type": "text",
      "show_data_tab": true
    }
  ]
}

出典・ライセンス

License:
MIT

このコードは Shopify 著作の MIT ライセンスソースです。 原本の著作権は Shopify が保有します。日本語訳は ALSEL によるものです。

関連項目

📘 公式リファレンス🏷️ リファレンス/タグ中級

doc タグ(テンプレートの注釈・ドキュメント)

Liquid テンプレート内にドキュメンテーションコメントを埋め込むタグ。`{% doc %}` ~ `{% enddoc %}` に囲まれたコンテンツは画面に出力されず、内部の Liquid コードは解析されるが実行されない。コード補完、リンティング、インラインドキュメント機能の実装を支援する。

📁 theme-liquid-docs·MIT·12
📘 公式リファレンス🏷️ リファレンス/タグ初級

include タグ(スニペットを埋め込む)

スニペットファイルを Liquid テンプレート内に埋め込んでレンダリングする。埋め込み先の変数にアクセス・変更できるため、親テンプレートと子スニペット間でデータを直接共有する。

📁 theme-liquid-docs·MIT·17
📘 公式リファレンス🏷️ リファレンス/タグ中級

javascript タグ(セクション・ブロック内のコード)

セクション、ブロック、スニペット内に JavaScript コードを記述するタグ。このタグ内に書いた JavaScript は Shopify のテーマビルドシステムにより自動的に読み込まれて実行される。

📁 theme-liquid-docs·MIT·17
📘 公式リファレンス🏷️ リファレンス/タグ初級

sections タグ(セクショングループを描画)

セクショングループをテーマのレイアウト内で描画するタグ。レイアウトファイル内に配置して、複数のセクションをグループ化した内容を出力する。

📁 theme-liquid-docs·MIT·17
📘 公式リファレンス🏷️ リファレンス/タグ初級

stylesheet タグ(CSS定義)

セクション、ブロック、スニペット内で CSS スタイルを定義するタグ。各ファイルにつき1つだけ記述でき、定義した CSS はそのコンポーネント固有の外側スコープで読み込まれて実行される。

📁 theme-liquid-docs·MIT·17
📘 公式リファレンス🏷️ リファレンス/タグ初級

break タグ(ループの中断)

for ループの反復処理を途中で停止するタグ。指定した条件に達したら以降の反復をスキップして、ループを抜ける。

📁 theme-liquid-docs·MIT·23