🚀
【Shopify基礎構築③】 特定のページだけにコードを適用させる
この記事では、Shopifyで'index'(トップページ)や'blog'(ブログ記事)などの特定のページだけにコードを適用させる方法を紹介します。
使用するオブジェクト
requestオブジェトを使用します。
特定のページに適用させる場合
以下のコードを使用します。
{% if request.page_type == 'template' %}
//適用させるコード
{% endif %}
templateには、
404・article・blog・captcha・cart・collection・list-collections・customers/account・customers/activate_account・customers/addresses・
customers/login・customers/order・customers/register・customers/reset_password・gift_card・index・page・password・policy・product・search
が入ります。
例:'index'(トップページ)に適用させる場合
{% if request.page_type == 'index' %}
//'index'(トップページ)に適用させる処理
{% endif %}
pathで適用させる場合
例えば、collectionのjuiceというハンドルのコレクションだけ表示させる場合を考えます。
この場合のURLは
https://shopify.com/collections/juice
となります。
この場合、以下のコードを使用します。
{% if request.path == '/collections/juice' %}
//コレクション[juice]だけに適用させるコード
{% endif %}
ほかにもblogs/○○(ブログ記事のhandle)やpages/○○(ページのhandle)などにも適用させることができます。
Shopifyの構築を承ります!
Shopifyで実装したいデザインなどがござましたら、お気軽にご相談、お問い合わせくださいませ!
Discussion