Capture page.title and filter product tags

Solved
Highlighted
Excursionist
47 3 3

I tag all my products with car model name so customers can be able to filter products based on car.

Example tag: * CarBrand CarModel Year

I add the asterisk sign before these tags.

 

I have a page (with my own created template) for each car model. The car page title is the tag without the (*).

Example title: CarBrand CarModel Year

 

I want to show filtered products based on tag on these pages. Why doesnt the liquid below work?

 

{% assign astriks = "*" %}
{% assign theCar = page.title %}
{% capture theCarTag %}
{{ astriks }} {{ theCar }}
{% endcapture %}

{% for product in collections.produktguiden.products %}
{% if product.tags contains theCarTag %}
<li> {{ product.title }}</li>
{% endif %}
{% endfor %}

When i output the {{ theCarTag }} it looks good (as the tag) but it doesn't work if filtering product.tags.

 

0 Likes
Highlighted
Excursionist
47 3 3

This is an accepted solution.

This works

 

{% capture theCarTag %}* {{ page.title }}{% endcapture %}

{% for product in collections.produktguiden.products %}
{% if product.tags contains theCarTag %}
<li> {{ product.title }}</li>
{% endif %}
{% endfor %}
0 Likes
Highlighted
New Member
4 0 0

Can we use tags filtering on a search page ? please help

0 Likes