Why some Dynamic variables doesn't work in global collection object?

In the below code, I can not get collection object which has hyphen(-) in its handle. Pleasae check attached image of tabs where I can get some collections and some not.

{% assign sidebar_array = sidebar_string | split:"," %}
                 {% for collection_handle in sidebar_array %}
                 {% assign collection_obj = collections[collection_handle] %}
                 {{collection_obj}}
                 
                   
                     {{ collections[collection_handle].title }}
                     {{ collections[collection_handle].all_products_count }} 
                   
                 

                 {% endfor %}

Without seeing the collection handle or a copy and paste of that array contents we’d be assuming the hyphen is the problem.

It might not be. Your code also seems to assume the collection exists which also might not be the case.

1 Like

@Jason , yes you are right. the issue is with handles which has hyphen in it. I can not find its solution. I faced this issue so many times but couldn’t post in community.

below is the updated code.

{% assign sidebar_string = “fresh-vine,albarino,allevine,alzania,charlotte-vine” %}
{% assign sidebar_array = sidebar_string | split:“,” %}
{% for collection_handle in sidebar_array %}
{% assign collection_obj = collections[collection_handle] %}
{{collection_obj}}

{{ collections[collection_handle].title }} {{ collections[collection_handle].all_products_count }}
{% endfor %}

(note: all assigned array of collection handles in above given liquid code do exist, no collection is empty and all the collection is published for “online store”)