📘 公式リファレンス📦 リファレンス/オブジェクト初級
search オブジェクト
ストアフロントの検索ページで、入力された検索キーワード、検索結果、フィルター、ソートオプションを取得するオブジェクト。
用途
検索ページ(search テンプレート)で、ユーザーが入力したキーワードに対して商品・ページ・ブログ記事を表示し、フィルターやソート機能を提供するとき。
設置場所
templates/search.liquid 内で `{{ search.terms }}`、`{{ search.results }}`、`{{ search.filters }}` のように直接参照する。results 内の各アイテムは `{% for item in search.results %}` でループし、`{{ item.title }}`、`{{ item.object_type }}`、`{{ item.url }}` などでアクセスする。
注意点
search.results 内のアイテムは article、page、product の3種類が混在するため、`item.object_type` で型判定してからプロパティにアクセスする必要がある。検索結果が1000件を超える場合、search.filters 配列は空になるため、大規模ストアでは手動フィルターの構築を検討する。paginate タグで最大50件/ページまで指定でき、超える場合は 50 に自動制限される。
仕様
182 行 / json{
"access": {
"global": false,
"parents": [],
"template": [
"search"
]
},
"deprecated": false,
"deprecation_reason": "",
"description": "To learn about storefront search and how to include it in your theme, refer to [Storefront search](/themes/navigation-search/search).",
"properties": [
{
"deprecated": false,
"deprecation_reason": "",
"description": "> Tip:\n> Use the [`highlight` filter](/docs/api/liquid/filters/highlight) to highlight the search terms in search result content.",
"examples": [],
"return_type": [
{
"type": "string",
"name": "",
"description": "",
"array_value": ""
}
],
"summary": "The entered search terms.",
"name": "terms"
},
{
"deprecated": false,
"deprecation_reason": "",
"description": "Only filters that are relevant to the current search results are returned. If the search results contain more than 1000\nproducts, then the array will be empty.\n\n> Tip:\n> To learn about how to set up filters in the admin, visit the [Shopify Help Center](https://help.shopify.com/manual/online-store/themes/customizing-themes/storefront-filters).",
"examples": [],
"return_type": [
{
"type": "array",
"name": "",
"description": "",
"array_value": "filter"
}
],
"summary": "The filters that have been set up on the search page.",
"name": "filters"
},
{
"deprecated": false,
"deprecation_reason": "",
"description": "",
"examples": [],
"return_type": [
{
"type": "boolean",
"name": "",
"description": "",
"array_value": ""
}
],
"summary": "Returns `true` if a search was successfully performed. Returns `false` if not.",
"name": "performed"
},
{
"deprecated": false,
"deprecation_reason": "",
"description": "An item can be an [`article`](/docs/api/liquid/objects/article), a [`page`](/docs/api/liquid/objects/page), or a\n[`product`](/docs/api/liquid/objects/product).\n\n> Tip:\n> Use the [paginate](/docs/api/liquid/tags/paginate) tag to choose how many results to show per page, up to a limit of 50.",
"examples": [
{
"name": "Search result `object_type`",
"description": "Search results have an additional `object_type` property that returns the object type of the result.",
"syntax": "",
"path": "/search?q=potion",
"raw_liquid": "{% for item in search.results %}\n<!-- Result {{ forloop.index }}-->\n<h3>\n {{ item.title | link_to: item.url }}\n</h3>\n\n{% if item.object_type == 'article' -%}\n {%- comment -%}\n 'item' is an article\n All article object properties can be accessed.\n {%- endcomment -%}\n\n {% if item.image -%}\n <div class=\"result-image\">\n <a href=\"{{ item.url }}\" title=\"{{ item.title | escape }}\">\n {{ item | image_url: width: 100 | image_tag }}\n </a>\n </div>\n {% endif %}\n{%- elsif item.object_type == 'page' -%}\n {%- comment -%}\n 'item' is a page.\n All page object properties can be accessed.\n {%- endcomment -%}\n{%- else -%}\n {%- comment -%}\n 'item' is a product.\n All product object properties can be accessed.\n {%- endcomment -%}\n\n {%- if item.featured_image -%}\n <div class=\"result-image\">\n <a href=\"{{ item.url }}\" title=\"{{ item.title | escape }}\">\n {{ item.featured_image | image_url: width: 100 | image_tag }}\n </a>\n </div>\n {% endif %}\n{%- endif -%}\n\n<span>{{ item.content | strip_html | truncatewords: 40 | highlight: search.terms }}</span>\n{% endfor %}",
"parameter": false,
"display_type": "text",
"show_data_tab": true
}
],
"return_type": [
{
"type": "untyped",
"name": "",
"description": "",
"array_value": ""
}
],
"summary": "The search result items.",
"name": "results"
},
{
"deprecated": false,
"deprecation_reason": "",
"description": "",
"examples": [],
"return_type": [
{
"type": "number",
"name": "",
"description": "",
"array_value": ""
}
],
"summary": "The number of results.",
"name": "results_count"
},
{
"deprecated": false,
"deprecation_reason": "",
"description": "",
"examples": [
{
"name": "Output the sort options",
"description": "",
"syntax": "",
"path": "/search?q=potion",
"raw_liquid": "{%- assign sort_by = search.sort_by | default: search.default_sort_by -%}\n\n<select>\n{%- for option in search.sort_options %}\n <option\n value=\"{{ option.value }}\"\n {%- if option.value == sort_by %}\n selected=\"selected\"\n {%- endif %}\n >\n {{ option.name }}\n </option>\n{% endfor -%}\n</select>",
"parameter": false,
"display_type": "text",
"show_data_tab": true
}
],
"return_type": [
{
"type": "array",
"name": "",
"description": "",
"array_value": "sort_option"
}
],
"summary": "The available sorting options for the search results.",
"name": "sort_options"
},
{
"deprecated": false,
"deprecation_reason": "",
"description": "If there's no `sort_by` URL parameter, then the value is `nil`.",
"examples": [],
"return_type": [],
"summary": "The sort order of the search results. This is determined by the `sort_by` URL parameter.",
"name": "sort_by"
},
{
"deprecated": false,
"deprecation_reason": "",
"description": "",
"examples": [],
"return_type": [
{
"type": "string",
"name": "",
"description": "",
"array_value": ""
}
],
"summary": "The default sort order of the search results, which is `relevance`.",
"name": "default_sort_by"
},
{
"deprecated": false,
"deprecation_reason": "",
"description": "A search can be performed on the following object types:\n\n- [`article`](/docs/api/liquid/objects/article)\n- [`page`](/docs/api/liquid/objects/page)\n- [`product`](/docs/api/liquid/objects/product)\n\n> Note:\n> The types are determined by the [`type` query parameter](/api/ajax/reference/predictive-search#query-parameters).",
"examples": [],
"return_type": [
{
"type": "array",
"name": "",
"description": "",
"array_value": "string"
}
],
"summary": "The object types that the search was performed on.",
"name": "types"
}
],
"summary": "Information about a storefront search query.",
"name": "search",
"examples": [],
"json_data": {
"path": "/search?q=potion",
"handle": "search",
"data_from_file": ""
},
"return_type": []
}出典・ライセンス
- Repository:
- https://github.com/Shopify/theme-liquid-docs
- 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 行