Liquid Snippets by ALSEL
📘 公式リファレンス📦 リファレンス/オブジェクト初級

template オブジェクト

現在レンダリング中のテンプレートの種類(product、collection など)と、カスタムテンプレートを使用している場合はその名前を取得するオブジェクト。

用途
ページの種類に応じた条件分岐や、カスタムテンプレートの有無を判定して表示内容を切り替えたいとき。例えば商品ページだけ特定の要素を表示したり、カスタム suffix が付いている場合に異なるレイアウトを適用する場合に使う。
設置場所
theme.liquid などのテンプレート内で `{{ template.name }}` で現在のテンプレート種類を参照、`{{ template.suffix }}` でカスタムテンプレート名を、`{{ template.directory }}` でディレクトリ名を取得できる。通常は `{% if template.name == 'product' %}` のような条件分岐で使用する。
注意点
template.suffix はデフォルトテンプレート使用時は nil を返すため、`if template.suffix` で値の有無を確認してから参照する。template.directory は `/templates` 直下のテンプレートの場合 nil になり、`customers/account` のような階層ディレクトリに配置されたテンプレートのみ値が入る。template.name は 404、article、blog、cart、collection、list-collections、customers/account(ほか customers/ 系)、gift_card、index、page、password、product、search の19種類に限定される。
タグ:templateconditionalpage-type

仕様

177 行 / json
{
  "access": {
    "global": true,
    "parents": [],
    "template": []
  },
  "deprecated": false,
  "deprecation_reason": "",
  "description": "",
  "properties": [
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "",
      "examples": [],
      "return_type": [
        {
          "type": "string",
          "name": "404",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "article",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "blog",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "cart",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "collection",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "list-collections",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "customers/account",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "customers/activate_account",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "customers/addresses",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "customers/login",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "customers/order",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "customers/register",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "customers/reset_password",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "gift_card",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "index",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "page",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "password",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "product",
          "description": "",
          "array_value": ""
        },
        {
          "type": "string",
          "name": "search",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "The name of the template's [type](/docs/themes/architecture/templates#template-types).",
      "name": "name"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "Returns `nil` if the default template is being used.",
      "examples": [],
      "return_type": [
        {
          "type": "string",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "The custom name of an [alternate template](/themes/architecture/templates#alternate-templates).",
      "name": "suffix"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "Returns `nil` if the template's parent directory is `/templates`.",
      "examples": [],
      "return_type": [
        {
          "type": "string",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "The name of the template's parent directory.",
      "name": "directory"
    }
  ],
  "summary": "Information about the current [template](/docs/themes/architecture/templates).",
  "name": "template",
  "examples": [],
  "json_data": {
    "path": "/products/health-potion",
    "handle": "template",
    "data_from_file": ""
  },
  "return_type": []
}

出典・ライセンス

License:
MIT

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

関連項目

📘 公式リファレンス📦 リファレンス/オブジェクト初級

content_for_header オブジェクト

Shopify が必要とするスクリプト(分析・チェックアウト・言語設定など)をすべて動的に出力するオブジェクト。theme.liquid の <head> タグ内に埋め込む必須要素。

📁 theme-liquid-docs·MIT·20
📘 公式リファレンス📦 リファレンス/オブジェクト中級

metaobjects オブジェクト

ストア全体のメタオブジェクト定義にアクセスするグローバルオブジェクト。個別のメタオブジェクトはタイプとハンドルで参照でき、メタオブジェクト定義のエントリをループで反復処理できる。

📁 theme-liquid-docs·MIT·20
📘 公式リファレンス📦 リファレンス/オブジェクト初級

additional_checkout_buttons オブジェクト

PayPal Express Checkout など、オフサイト決済に対応した外部決済プロバイダーがストアに設定されているかを真偽値で返す。`content_for_additional_checkout_buttons` と組み合わせて、該当するチェックアウトボタンを条件付きで表示する。

📁 theme-liquid-docs·MIT·27
📘 公式リファレンス📦 リファレンス/オブジェクト初級

canonical_url オブジェクト

現在のページの正規 URL を取得するオブジェクト。Google などの検索エンジンに対してどのページ版が正規であるかを指定するために使用する。

📁 theme-liquid-docs·MIT·27
📘 公式リファレンス📦 リファレンス/オブジェクト初級

content_for_index オブジェクト

ホームページに表示するセクションの内容を動的に返すオブジェクト。Liquid インデックステンプレートで必ず使用する。

📁 theme-liquid-docs·MIT·27
📘 公式リファレンス📦 リファレンス/オブジェクト初級

content_for_additional_checkout_buttons オブジェクト

PayPal、Apple Pay、Google Pay など複数の決済プロバイダが有効になっているとき、その決済ボタンを HTML として出力するオブジェクト。`additional_checkout_buttons` で有無を判定したうえで、このオブジェクトで実際のボタンを表示する。

📁 theme-liquid-docs·MIT·27