# {% 〇〇 %}内での変数展開について

**URL:** <https://community.shopify.com/t/topic/8500>\
**Category:** 技術的なQ＆A\
**Created:** [January 17, 2020, 3:12am UTC](https://community.shopify.com/t/topic/8500 "2020-01-17T03:12:00Z")\
**Posts on this page:** 3\
**Page:** 1

## AI-generated summary

ブログのタグページで、現在のブログタグと同名のタグを持つ商品だけを動的に表示したい、というLiquidの記述方法が主題です。`collections['all'].products` を走査し、商品タグと現在のブログタグを比較する実装が試されていました。

要点:
- `{{ current_tags }}` は画面出力用で、`{% if %}` などのLiquidタグ内では `current_tags` とそのまま変数名で書く。
- 比較は `tag == current_tags` でよい。
- `{{ }}` は値の表示、`{% %}` は制御構文という使い分けが確認された。

結果:
- ` {% if tag == current_tags %} ` で解決。
- 当初うまくいかなかった原因は、商品タグ名とブログタグ名のテスト登録時に半角スペースの有無が一致していなかったため。
- 議論は解決済みで、追加の未解決事項は特に残っていません。

<div class="post-metadata">

**Author:** ![akatuki](https://yyz1.discourse-cdn.com/shopifyforum/user_avatar/community.shopify.com/akatuki/32/199931_2.png) [@akatuki](https://community.shopify.com/u/akatuki)\
**Post date:** [January 17, 2020, 3:12am UTC](https://community.shopify.com/t/topic/8500/1 "2020-01-17T03:12:00Z")

</div>

■実現したい事

ブログタグページで、ブログタグ名と商品タグ名が一致する商品を表示したいです。

例）

・商品A 登録タグ：りんご

・ブログA 登録タグ：りんご

[https://〇.myshopify.com/blogs/blog/tagged/りんご](https://blackbrickstore.myshopify.com/blogs/information/tagged/trunk-show)

のブログタグページ内で、同一タグを持っている「商品A」を表示。

■試したこと

```auto
{% for product in collections['all'].products %}
  {% for tag in product.tags %}
    {% if tag == 'りんご' %}
	<a href="{{ product.url }}">{{ product.title }}</a>      
    {% endif %}
  {% endfor %}
{% endfor %}

```

⇒このコードで同一タグを持つ商品の出力はできましたが、ブログタグページ毎に動的に動作させるために{% if tag == ‘りんご’ %}のりんごの部分の値を変数で対応させたいです。

{{current\_tags}}で現在表示のブログタグページのタグは取得できますが、以下のように{% 〇〇 %}内で変数展開ができません。

```auto
{% if tag == current_tags %}
{% if tag == ’{{current_tags}}’ %}

```

{% 〇〇 %}内での変数展開の方法などがございましたら、ご教示いただけますでしょうか。

---

<div class="post-metadata">

**Author:** ![junichiokamura](https://yyz1.discourse-cdn.com/shopifyforum/user_avatar/community.shopify.com/junichiokamura/32/299737_2.png) [@junichiokamura](https://community.shopify.com/u/junichiokamura)\
**Post date:** [January 20, 2020, 8:45am UTC](https://community.shopify.com/t/topic/8500/2 "2020-01-20T08:45:20Z")

</div>

```auto
{% if tag == current_tags %}

```

ではどうでしょうか？ {{}}は、テンプレート内で展開させる方法で、Liquid内でコードの変数として利用する場合は、名称を直接指定することになると思います。

---

<div class="post-metadata">

**Author:** ![akatuki](https://yyz1.discourse-cdn.com/shopifyforum/user_avatar/community.shopify.com/akatuki/32/199931_2.png) [@akatuki](https://community.shopify.com/u/akatuki)\
**Post date:** [January 21, 2020, 2:00am UTC](https://community.shopify.com/t/topic/8500/3 "2020-01-21T02:00:32Z")

</div>

{% if tag == current\_tags %}

で問題なく解決いたしました。有り難うございます。

凡ミスで商品タグとブログタグの登録タグ名を半角スペース有り無しで登録してテストしていました･･･。
