Is it possible to display a collection product count on a standard non-collection page

Is it possible to display a collection product count on a standard non-collection page

ahopkins
Shopify Partner
9 0 0

I have a page which contains hard coded collection links. Due to the complexity of the collection structure, they had to be hard coded inside a template. What I'd like to know is whether it's possible to display the product count for a set collection on this page?

 

The current layout of the collection template looks something like this 

 

Title

 

Blocks of sub-collections to further filter down (There are around 8 of these and are hard coded into a template)

 

List of products in the parent collection

 

Using the layout above as an example, in some cases I may only have 3 products in the entire parent collection. Meaning some of the sub-collections are going to be empty. What I'd like to be able to do is to hide some of these if their product count is empty. This is what I'm struggling with. I'll need to wrap a conditional around every sub-collection block but I would need to somehow define or assign the collection in order to test the conditional. But because the blocks are not dynamic, they have no real 'link' to a collection.

 

Does anyone have any advice on what I could do here? Any help much appreciated.

Reply 1 (1)
ahopkins
Shopify Partner
9 0 0

Hello again, 

 

Unfortunately I have not been able to get the code to display/no display what I need. I tried implementing the code you provided into one of my templates. To begin with I just tested the code isolated from the rest of the page as such

 

<!-- Title -->

<!-- Blocks of sub-collections -->
{% assign collections = 'aerial-firefighting-ac313' %}

{% for collection_handle in collections %}
{% assign collection = collections[collection_handle] %}

{% if collection.products_count > 0 %}
<div class="sub-collection-block">
<h2>{{ collection.title }}</h2>
<!-- Display collection content here -->
</div>
{% endif %}
{% endfor %}

<!-- List of products in the parent collection -->

 

 

The only thing that's different  is that I have removed the array of handles in place of just one value; 'aerial-firefighting-ac313' 

 

I know by looking in the collections list that 'aerial-firefighting-ac313' has 2 products assigned to it.

 

So by that logic, the <h2> title of the collection should display. Unfortunately it didn't. Could there be something additional preventing this?