Capturing Article.Handle and using it to find a Collection with that handle

Hi all. I’m a bit stuck on this one. I’ve done something before but cannot for the life of me remember how to do it. Any help is greatly apprecited.

I’m trying to show a Collection on a Blog Article Page. The Collection I need to show has the same handle as the blog article.

The Article handles will be along the lines of ‘nigel-burke’. So the Collection I am trying to show on that Article page is called ‘Nigel Burke’ along with ‘-ambassador’ at the end of the handle too. I’m then wanting to show the products in that particular collection on that particular article page.

This is the code I am trying to use…

{% capture my_variable %}{{ article.title | downcase | replace: ’ ‘,’-’ | append: ‘-ambassador’}}{% endcapture %}

{% for product in collections.[my_variable].products %} {{ product.title }} {% endfor %}

But it’s not working. Any help is greatly appreciated.

Nigel

Hi @Nigel_Burke ,

This is Kate from PageFly - Landing page builder, I’d like to suggest this idea:
You can try below code:

{% capture my_variable %}{{ article.handle | append: '-ambassador'}}{% endcapture %}

{% for product in collections[my_variable].products %}
{{ product.title }}
{% endfor %}

I hope it would help you
Best regards,

Kate | PageFly

Kate, thank you for taking the time to help me with this.

I managed to get it working with your help, thanks. There was a little change needed here and there as you weren’t to know a few things it needed to do too.

You set me off in the right direction though, so thank you again!

This is how it ended up working for me…

{% capture my_variable %}{{ article.title | downcase | replace: ’ ‘,’-’ | append: ‘-ambassador’}}{% endcapture %}

{% for product in collections[my_variable].products %} {{ product.title }} {% endfor %}
1 Like