Solved

Showing a metafield on a collection page based on collection

abe2
Tourist
6 0 2

Hi - I am trying to add some text to a collection page, based on what collection the product is in.

We sell coffee, so if a visitor visits the coffee collection it should show the taste notes on the collection page. If the visitor goes to the equipment collection nothing should show.

I can add the taste notes field in, it just shows on every collection ;(

Thanks

Accepted Solution (1)
Kyle_W
Shopify Expert
172 26 105

This is an accepted solution.

I just want to show one text line under above the price. do I really need to create new collection templates to do that?

@abe2 If there's only a slight difference between the collection pages, then you don't really need to create separate collection templates. Instead, you could use some Liquid control flow tags to show different content based on the collection. For example: 

{% if collection.handle == 'coffee' %}
  do something
{% endif %}

Docs for reference:

Hopefully this helps!

 

Kyle W | Helium
Helium builds apps that thousands of merchants depend on:
- Customer Fields ✪✪✪✪✪ (300+ reviews)
- Meteor Mega Menu ✪✪✪✪✪ (200+ reviews)

View solution in original post

Replies 7 (7)

suyash1
Shopify Partner
9078 1129 1479

@abe2 - it is because shopify shares same template files for all collections. 

To have different description, you will need to have different templates for different collections.  If there are too many collections, then it is not feasible.

To build shopify pages use pagefly
You are welcome to contact me - suyash.patankar@gmail.com , My timezone is GMT+5:30.
paranormal story video using AI
abe2
Tourist
6 0 2

Hi, yes, it shared the same collection page. We only have 3 collections in total. Coffee, Coffee Subscriptions and Equipment. 

suyash1
Shopify Partner
9078 1129 1479

@abe2 - then you need 3 collection templates... each for one category and you can set description for it

To build shopify pages use pagefly
You are welcome to contact me - suyash.patankar@gmail.com , My timezone is GMT+5:30.
paranormal story video using AI
abe2
Tourist
6 0 2

Thank you. Just to be clear - everything about the collection pages is fine - I just want to show one text line under above the price. 
do I really need to create new collection templates to do that?

Kyle_W
Shopify Expert
172 26 105

This is an accepted solution.

I just want to show one text line under above the price. do I really need to create new collection templates to do that?

@abe2 If there's only a slight difference between the collection pages, then you don't really need to create separate collection templates. Instead, you could use some Liquid control flow tags to show different content based on the collection. For example: 

{% if collection.handle == 'coffee' %}
  do something
{% endif %}

Docs for reference:

Hopefully this helps!

 

Kyle W | Helium
Helium builds apps that thousands of merchants depend on:
- Customer Fields ✪✪✪✪✪ (300+ reviews)
- Meteor Mega Menu ✪✪✪✪✪ (200+ reviews)
abe2
Tourist
6 0 2

That’s the one. Thank you! I don’t suppose you have a reference for building different collection page templates?

 

Kyle_W
Shopify Expert
172 26 105

You're most welcome, @abe2!

Here's a link to Shopify's docs for theme templates: https://shopify.dev/themes/architecture/templates 

Kyle W | Helium
Helium builds apps that thousands of merchants depend on:
- Customer Fields ✪✪✪✪✪ (300+ reviews)
- Meteor Mega Menu ✪✪✪✪✪ (200+ reviews)