How to {{output}} in collection title like collections.{{customer.id}}.products

Solved
Highlighted
Explorer
96 0 4

Short: If a customer.tag contains "1234", I want to show products in collection "1234" on the customer/account page without specifying the collections.1234.products in liquid...but rather by outputting like so:

 

collections.{{ customer.tags.first }}.products

 

Long: I have collections with the same exact titles as customer.tags.first (intentionally!). I need to output the products of those collections on the customer/account page IF the customer has the matching tag.

 

How can I achieve something like this?

 

{% if customer %}{{ customer.tags.first }}

{% for product in collections.{{ customer.tags.first }}.products %}

Hello World.

{% endif %}

{% endfor %}

Thanks!

0 Likes
Highlighted
Shopify Partner
43 4 8

Try:

 

{% if customer %}{{ customer.tags.first }}
  {% for product in collections[customer.tags.first].products %}
    {{ product.title }}
  {% endfor %}
{% endif %}
Need some help or work done? Hire me!
Highlighted
Explorer
96 0 4

@Marslan 

 

Thanks - very close! The only problem with this is it is outputting customer.tags.first above the product title...is there a way I can hide customer.tags.first so that it doesn't show up, but the product titles do...?

0 Likes
Highlighted
Shopify Partner
43 4 8

This is an accepted solution.

Oh I thought it was intentionally there to show the collection title, just remove 

{{ customer.tags.first }}

from first line

and make it

{% if customer %}
  {% for product in collections[customer.tags.first].products %}
    {{ product.title }}
  {% endfor %}
{% endif %}

 

Need some help or work done? Hire me!
Highlighted
Explorer
96 0 4

Thanks @Marslan!

Another option for anyone in the same boat:

I realized I could remove {% if customer %} and {% endif %} entirely because the correct collections will always only display for customers logged in with unique tags because the collection is called:

collections[customer.tags.first].products

Thus a different collection will display depending on what the customer.tags.first is.

So my final code looks like this:

{% for product in collections[customer.tags.first].products %}
{{ product.title }}
{% endfor %}

 

0 Likes
Highlighted
Highlighted
Shopify Partner
43 4 8

@zoabijoux76 wrote:

Hello 

can you tell me how i delete this collection:

https://zoabijoux.fr/collections

 

zoabijoux.fr


@zoabijoux76 Delete what exactly? The /collections?

This is your main collection page, you shouldn't delete it, just hide it or customize it according to your needs.

Need some help or work done? Hire me!
Highlighted
New Member
4 0 0

but it is empty
how do i personalize it please ? 

0 Likes
Highlighted
Shopify Partner
43 4 8

Depending on what kind of customization you need, you could use the theme editor.

 

Go to Store Dashboard > Online Store > Customize > Collection Lists

You will have some options available there.

 

If that wasn't effective, consider hiring someone because this could require significant technical knowledge depending on what you want exactly and can't be crammed into this post.

Need some help or work done? Hire me!
0 Likes
Highlighted
New Member
4 0 0

thanks for your replay 


@Marslan wrote:

Depending on what kind of customization you need, you could use the theme editor.

 

Go to Store Dashboard > Online Store > Customize > Collection Lists

You will have some options available there.

 

If that wasn't effective, consider hiring someone because this could require significant technical knowledge depending on what you want exactly and can't be crammed into this post.


 

0 Likes