To access specific collection attributes, you must know collection handle and use this kind of code :
{{ collections['the-handle'].url }}
So to achieve what you want to do, here is what you could do:
{% assign collection_handle = 'the-handle-of-collection-you-want' %}
{% for product in collections[collection_handle].products %}
Do your stuff
{% endfor %}
Note that you cannot access a collection through its title. Only handle.
Learning more about what's handle: https://help.shopify.com/themes/liquid/basics/handle
HTH
Answer from Alice Girard on Stack OverflowTo access specific collection attributes, you must know collection handle and use this kind of code :
{{ collections['the-handle'].url }}
So to achieve what you want to do, here is what you could do:
{% assign collection_handle = 'the-handle-of-collection-you-want' %}
{% for product in collections[collection_handle].products %}
Do your stuff
{% endfor %}
Note that you cannot access a collection through its title. Only handle.
Learning more about what's handle: https://help.shopify.com/themes/liquid/basics/handle
HTH
use dash(-) instead of space in collection name like "sale potions" then it will be "sale-potions"
{% for product in collections['sale-potions'].products %}
{{- product.title | link_to: product.url }}
{% endfor %}
You can now retrieve a product via a handle using the following:
{% assign someProduct = all_products.some-handle %}
Documentation
Just to update for anyone just finding this, you can now reference products directly via handle by all_products['handle'] as per this response on their Shopify/liquid repo.
You have access to the current_tags, refer to docs: https://shopify.dev/docs/themes/liquid/reference/objects/current-tags
This will return an array of all the tags you are viewing at the moment (in case you are viewing more than one tag).
So your check will be:
{% if current_tags contains 'mens' %}
do something
{% endif %}
That's pretty much the just of it.
I really like how the menu is coming along! Here are some ideas you could consider for your category specific menu, if you've not gotten where you want yet.
For your url strategy, what you're looking for is handle. Handles are specific to liquid. https://shopify.dev/docs/themes/liquid/reference/basics/handle
You could make a custom collection template if those 2 categories need to be fairly different: https://shopify.dev/tutorials/customize-theme-create-alternate-templates. If you do that, then you can use
template_prefixfrom the collection object.Assign a variable outside your loop and then set it inside the loop like:
{% assign is_mens = false %} {% for tag in product.tags %} {% if tag contains 'mens' %} {% assign is_mens = true %} {% endif %} {% endfor %}
then {% if is_mens %} or {% unless is_mens %} for your dynamic content, or a case statement to define content specific to categories in your menu.
Hope this helps!
In order to get the CURRENT collection, you MUST have the collection handle in your URL.
So for example if the product URL is something like so /collections/COLLECTION_HANDLE/products/PRODUCT_HANDLE you will have access to the current collection.
In your case since you don't have access to the collection title I assume that your URL is just /products/PRODUCT_HANDLE.
This means that you are generating the wrong URL's ( not wrong, but not full ). You must look for product.url in your collection and add the filter within: collection.
So your collection liquid code should look something like this
{% for product in collection.products %}
... SOME OUTPUT ...
<a href="{{ product.url | within: collection }}">Details</a>
{% endfor %}
This will force your product url to include the collection URL as well.
Try it if your URL in this format "/collections/COLLECTION_HANDLE/products/PRODUCT_HANDLE"
Try This:
This product is in the {{ collection.title }} Collection.