How can I list products on a static page that are tagged by a tag that has the same name as my page?

61 Views Asked by At

I'd like to list products on my static page called "Haarentfernung". Each product that should be featured has a same named tag called "Haarentfernung".

So far I've managed to get the Products with the tag 'Haarentfernung'.

{% paginate collections.all.products by 999 %}
   {%- assign allItems = collections.all.products -%}
     {%- for items in allItems -%}
       {% assign testItem = items.tags | where: 'Haarentfernung'%}
         <p>{{ testItem }}test1</p> 
     {% endfor %}
{% endpaginate %}

However I'd like to make it dynamic with the element page.title. But using {{ page.title }} inside the where filter doesn't work

{% paginate collections.all.products by 999 %}
   {%- assign allItems = collections.all.products -%}
     {%- for items in allItems -%}
       {% assign testItem = items.tags | where: {{ page.title }} %}
         <p>{{ testItem }}test1</p> 
     {% endfor %}
{% endpaginate %}

also doesn't work with when in apostrophes

{% paginate collections.all.products by 999 %}
   {%- assign allItems = collections.all.products -%}
     {%- for items in allItems -%}
       {% assign testItem = items.tags | where: '{{ page.title }}' %}
         <p>{{ testItem }}test1</p> 
     {% endfor %}
{% endpaginate %}

Is there a solution that is simpler? Maybe totally different approach?

1

There are 1 best solutions below

0
Charles C. On

the {{...}} is for rendering to HTML for the front end. It does not change {{page.title}} to a string in {% assign testItem = items.tags | where: {{ page.title }} %}

Remove the {{...}} in {{page.title}} will work.