Display page content based on selected product tag in collection filter

Solved
Highlighted
Excursionist
47 3 3

I have dropdown select displaying products tags starting with * on collection pages. The filter works but i want to show page content depending on selected product tag.

 

The dropdown filter:

<select id="carModelFilter" class="coll-filter select">
{% for tag in collection.tags %}
{% if current_tags contains tag and tag contains '*' %}
<option value="{{ tag | handle }}" selected>{{ tag | replace: "*", "" }}</option>
{% elsif tag contains '*' %}
<option value="{{ tag | handle }}">{{ tag | replace: "*", "" }}</option>
{% endif %}
{% endfor %}
</optgroup>
</select>

 

When an option/product tag is selected, the tag adds at the end of the url handle. Im trying to fetch the tag/url_handle to display page content with the same name.

{% for tag in collection.tags %}
{% if current_tags contains tag and tag contains '*' %}
{{ pages.["tag | handle"].content }}
{% endif %}
{% endfor %}

Doesn't work :( Anyone know how to achieve this?

0 Likes
Highlighted

Success.

Excursionist
47 3 3

Got it working

{% for tag in collection.tags %}
{% if current_tags contains tag and tag contains '*' %}
{% capture selectedCar %}{{ tag | handle }}{% endcapture %}
{{ pages.[selectedCar].content }}
{% endif %}
{% endfor %}
0 Likes