All things Shopify and commerce
I have a gift shop on shopify. In my main menu I have an 'Occasions' drop down and in the drop down there are 5 occasions - happy birthday, thanks, etc. Each page uses the same occasions template but should only pull in the gifts for the specific occasion. These are already set up in separate 'collections' like the Happy birthday collection. Is there a way of only using one collection template and pulling in collections to a page dynamically? The problem I have is every occasion page is showing the same collection from the template.
Hi @mariannemca,
You're right, it's inefficient to have separate templates for each occasion when they share a similar structure. Here's how you can use a single collection template to display different collections dynamically:
1. Use Liquid to Determine the Collection:
In your occasions.liquid template:
{% assign current_collection_handle = page.handle %} {% case current_collection_handle %} {% when 'happy-birthday' %} {% assign collection = collections.get('happy-birthday') %} {% when 'thanks' %} {% assign collection = collections.get('thanks') %} {% when 'graduation' %} {% assign collection = collections.get('graduation') %} {% when 'anniversary' %} {% assign collection = collections.get('anniversary') %} {% when 'sympathy' %} {% assign collection = collections.get('sympathy') %} {% else %} {% assign collection = collections.all %} {% endcase %} {% if collection %} <h2>{{ collection.title }}</h2> {% for product in collection.products %} {% endfor %} {% endif %}
Explanation:
2. Adjust Collection URLs:
3. Customize and Style:
By using this approach, you can effectively reuse a single template for all your occasion pages while dynamically displaying the products from the relevant collection.
Remember:
I hope this helps!
Let me know if you have any further questions.
Lily
Hey Community! As we jump into 2025, we want to give a big shout-out to all of you wh...
By JasonH Jan 7, 2025Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024