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
Learn how to expand your operations internationally with Shopify Academy’s learning path...
By Shopify Feb 4, 2025Hey Community, happy February! Looking back to January, we kicked off the year with 8....
By JasonH Feb 3, 2025Expand into selling wholesale with Shopify Academy’s learning path, B2B on Shopify: Lau...
By Shopify Jan 28, 2025