programmatically hide a collection?

edk
Excursionist
26 2 14

My homepage features a "New Arrivals" collection.  Sometimes we remove all of the items classed as new arrivals, because we are keeping that collection fresh.  

When the collection is empty, it shows an ugly set of blank images and prompts me to add some items.  

I don't want customers to see that.  I would like a way to hide that collection when there is no content.  

When I Customize my site, looking at the Home page, there is a column on the left of each section.  There is an eyeball icon on each section to make that section visible/invisible.  Is there a way to toggle that function programmatically?  

I assume this is a Section attribute, not one of Collection.  I don't see a file in the code for Section.  

My site is traditionalartstodaystore.org

Thanks

Ed K

0 Likes
CANDISOFT
Shopify Partner
986 142 447

gor that you need to wrap below code on your collevtion code.

{% unless collection.empty %}

{% endunless %}

For Contact : candisoft100@gmail.com
Want to customize Shopify storefront? Check the PageFly app
75,000+ Active Shopify merchants. TOP5 best Shopify Apps.
edk
Excursionist
26 2 14

No, I take it back - my mistake, problem not solved.  It doesn't work.  An empty collection still throws an ugly set of blank images up on my home page.  

I have another snippet in list-collections-template.liquid to prevent an empthy collection from appearing in a collection list.  That works.  And it fooled me for a minute and I thought the {% unless %} was the solution.  But no, neither of these solves the problem of an empty collection appearing on my home page.  

So I tried a work-around, by putting a collection list on the home page.  My snippet works on the collections list page, why not in a list somewhere else?  But no, the same thing happens, ugly placeholders.  

I have a hunch I need to hide the entire block.  

 

 

0 Likes
CANDISOFT
Shopify Partner
986 142 447

@edk , ok can you add me in your store so that i can check the code and fix it for free.

For Contact : candisoft100@gmail.com
Want to customize Shopify storefront? Check the PageFly app
75,000+ Active Shopify merchants. TOP5 best Shopify Apps.
0 Likes
edk
Excursionist
26 2 14

There appears to be no such item as collection.empty.  But there is collection.all_products_count. 

Found a way - what I was after was a way to inhibit the home page rendering anything to do with an empty collection.  But I could not find the code that was rendering the home page. 

However, I could find some code for custom content (custom-content.liquid).  That's a possible section on the home page, a container for images, HTML... and collections.  I loaded my collection into the custom content container, and yes, it appeared.  I removed my test item from the collection - ugly blank images.  

Here is the new code for custom-content.liquid, located inside a switch for the different types of content:

{% when 'collection' %}
{%- assign collection = collections[block.settings.collection] -%}

{% if collection.all_products_count > 0 %} <- added condition

<h1> {{collection.title}} </h1> <- need to render the title

{% include 'collection-grid-item' %} <- original include

{% endif %}

Now, with an empty collection - just a small bit of white space.  Add an item - collection title and link.  

0 Likes
CANDISOFT
Shopify Partner
986 142 447
Click to expand...
 

@edk can you share the link of the page please?

For Contact : candisoft100@gmail.com
Want to customize Shopify storefront? Check the PageFly app
75,000+ Active Shopify merchants. TOP5 best Shopify Apps.
0 Likes