# 商品個別ページで、その商品が属するタグを表示させる

**URL:** <https://community.shopify.com/t/topic/57636>\
**Category:** サンプルコード集（アプリ・テーマ）\
**Created:** [August 6, 2021, 3:00am UTC](https://community.shopify.com/t/topic/57636 "2021-08-06T03:00:53Z")\
**Posts on this page:** 5\
**Page:** 1

## AI-generated summary

商品詳細ページでタグを表示し、スペースを含むタグ（例：MICKEY MOUSE）のリンクが%20になり無効化される問題。添付スクリーンショットと該当商品URLで現象が確認された。

初期提案は表示テキストにreplaceフィルターを使う案だったが、URLのハンドルにスペースを含めることは不可（Shopifyのhandle仕様で空白・記号はハイフンへ変換）。

解決策：aタグのhrefにString filter「handleize」を適用し、タグ文字列を正しいハンドル（小文字化＋空白をハイフン化）へ整形する。例：/collections/all/{{ tag | handleize }}。アンカーテキストは #{{ tag }} のままで可。

補足：タグ名の変換を行うアプリ（Tag Manager）にも言及があったが、最終的な対応はhandleizeで十分。

結論：問題はhandleizeの適用で解決。議論はクローズ済みで未解決事項なし。

<div class="post-metadata">

**Author:** ![Anonymous\_f4d9c3948b8f04db09de840c50df25cb](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@Anonymous\_f4d9c3948b8f04db09de840c50df25cb](https://community.shopify.com/u/Anonymous_f4d9c3948b8f04db09de840c50df25cb)\
**Post date:** [August 6, 2021, 3:00am UTC](https://community.shopify.com/t/topic/57636/1 "2021-08-06T03:00:53Z")

</div>

商品個別ページで、その商品が属するタグを表示させるために、

product-template.liquidの中に、以下のコードを入れると概ね実現されるのですが、商品タグがスペースを含んだ場合にスペースを区切り文字と認識してしまうようです。解決できますでしょうか。タグをスペース無しで作るというのも考えたのですが、そうするとタグがSEOキーワードとして弱くなるかなと。

{% for tag in product.tags %}- [#{{ tag }}](https://community.shopify.com/collections/all/{{ tag }})
{% endfor %}

---

<div class="post-metadata">

**Author:** ![Jizo\_Inagaki](https://yyz1.discourse-cdn.com/shopifyforum/user_avatar/community.shopify.com/jizo_inagaki/32/149480_2.png) [@Jizo\_Inagaki](https://community.shopify.com/u/Jizo_Inagaki)\
**Post date:** [August 11, 2021, 11:53am UTC](https://community.shopify.com/t/topic/57636/2 "2021-08-11T11:53:56Z")

</div>

ご質問の趣旨を把握しかねていますが、記載されましたコードの以下の部分のハイフォンをスペースに置き換えたいということでしょうか？

```markup
#{{ tag }}

```

その場合は以下のようにフィルターを使えば一応スペースにはなるかと思います。

```markup
#{{ tag | replace: '-', ' ' }}

```

[https://shopify.dev/api/liquid/filters/string-filters#replace](https://shopify.dev/api/liquid/filters/string-filters#replace)

なお、URL末尾につくハンドルに関してスペースを加えた状態にしたいということであれば不可能だと思われます。  
詳細は以下を参照ください。

[https://shopify.dev/api/liquid/basics/handle](https://shopify.dev/api/liquid/basics/handle)

> By default, a handle is the object’s title in lowercase with any spaces and special characters replaced by hyphens (-).

以上ですが、使用経験はありませんが以下のアプリはタグ名を変換できるようなので、場所によっては利用できるかもしれません。

[https://apps.shopify.com/tag-manager?locale=ja](https://apps.shopify.com/tag-manager?locale=ja)

---

<div class="post-metadata">

**Author:** ![Anonymous\_f4d9c3948b8f04db09de840c50df25cb](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@Anonymous\_f4d9c3948b8f04db09de840c50df25cb](https://community.shopify.com/u/Anonymous_f4d9c3948b8f04db09de840c50df25cb)\
**Post date:** [August 12, 2021, 1:46am UTC](https://community.shopify.com/t/topic/57636/3 "2021-08-12T01:46:30Z")

</div>

ありがとうございます。

わかりにくい説明で申し訳ありません。

商品ページにタグが表示されて、それらはクリッカブルなのですが、途中にスペースを含むタグ、例えば MICKEY MOUSEなどで問題が発生します。

 ![スクリーンショット-2021-08-12-10.39.14.jpg](https://canada1.discourse-cdn.com/shopifyforum/original/3X/e/5/e565f3d7bb0e5ac085dbb3657d85c54015305b0b.jpeg)

[https://shop.robotrobot.com/products/17779292](https://shop.robotrobot.com/products/17779292)

この商品に対して４つのタグが設定してあり、そのうち ●MICKEY MOUSEだけが、途中にスペースを含んでいます。

タグのURLが

MICKEY MOUSE以外は、スペースを含んでおらず、以下のように問題ないのですが、

[https://shop.robotrobot.com/collections/all/McDonald’s](https://shop.robotrobot.com/collections/all/McDonald's)

MICKEY MOUSEのようにスペースを含んだ場合、スペースが%20になってしまい、URLが無効になってしまいます。

[https://shop.robotrobot.com/collections/all/MICKEY%20MOUSE](https://shop.robotrobot.com/collections/all/MICKEY%20MOUSE)

---

<div class="post-metadata">

**Author:** ![Jizo\_Inagaki](https://yyz1.discourse-cdn.com/shopifyforum/user_avatar/community.shopify.com/jizo_inagaki/32/149480_2.png) [@Jizo\_Inagaki](https://community.shopify.com/u/Jizo_Inagaki)\
**Post date:** [August 12, 2021, 3:01am UTC](https://community.shopify.com/t/topic/57636/4 "2021-08-12T03:01:18Z")

</div>

確認いただきありがとうございます。

つまりアンカーテキストではなく、aタグのhrefに設定するURLに関するご質問ということですね。

その場合は以下のようにString filterのhandleizeを使えば適切な状態に整形されると思います。

```markup
- #{{ tag }}

```

詳細は下記を確認ください。

[https://shopify.dev/api/liquid/filters/string-filters#handle-handleize](https://shopify.dev/api/liquid/filters/string-filters#handle-handleize)

---

<div class="post-metadata">

**Author:** ![Anonymous\_f4d9c3948b8f04db09de840c50df25cb](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@Anonymous\_f4d9c3948b8f04db09de840c50df25cb](https://community.shopify.com/u/Anonymous_f4d9c3948b8f04db09de840c50df25cb)\
**Post date:** [August 12, 2021, 6:17am UTC](https://community.shopify.com/t/topic/57636/5 "2021-08-12T06:17:58Z")

</div>

解決しました！ありがとうございます。
