I'm trying to create a navigation menu within shopify, where if a customer has tag 'X' and that tag IS a collection, then display the corresponding collection link in the menu. Though I'm not sure I'm understanding the use of the 'where' property properly.
I'm totally fresh to liquid so please excuse any blunders.
According to the doc's, located here. 'Where', creates an array including only the objects with a given property value, or any truthy value by default. So in theory I thought I could use this within my link array.
Here's the doc's example
All products:
{% for product in products %}
{{ product.title }}
{% endfor %}
{% assign kitchen_products = products | where: "type", "kitchen" %}
Kitchen products:
{% for product in kitchen_products %}
{{ product.title }}
{% endfor %}
Output:
All products:
- Vacuum
- Spatula
- Television
- Garlic press
Kitchen products:
- Spatula
- Garlic press
Here's my attempt
<!-- custom collection loop for sidebar navigation -->
{% if customer.tags != blank %}
{% assign link = linklists.main-collections.links | where: link.title, customer.tags %} // This line in particular...
{% for link in linklists.main-collections.links %}
{% assign outer_index = forloop.index %}
{% if link.links != blank %}
{% assign has_active_link = false %}
{% if link.active or link.child_active %}
{% assign has_active_link = true %}
{% endif %}
<li class="site-nav--has-submenu site-nav__item"></li>
{% else %}
<li class="site-nav__item {{ collection.handle }}-collection {% if link.active %} site-nav--active{% endif %}">
<a href="{{ link.url }}" class="site-nav__link" {% if link.active %} aria-current="page" {% endif %}>{{ link.title | escape }}</a>
</li>
{% endif %}
{% endfor %}
{% endif %}
<!-- / end custom collection loop for sidebar navigation -->
Any guidance on my issue here would greatly appreciated.
Further clarification:
Customer A has the tags Apple, Pear, Peach
Collections exist for Apple, Pear Peach
Expected Output:
<ul>
<li><a href="/apple">Apple</a></li>
<li><a href="/pear">Pear</a></li>
<li><a href="/peach">Peach</a></li>
</ul>