programmatically hide a collection?

edk
Excursionist
27 2 18

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

Replies 6 (6)

pioneer100
Shopify Partner
1119 145 481

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

{% unless collection.empty %}

{% endunless %}

If helpful, Please Like and accept The Solution.
edk
Excursionist
27 2 18

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.  

 

 

pioneer100
Shopify Partner
1119 145 481

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

If helpful, Please Like and accept The Solution.
edk
Excursionist
27 2 18

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.  

pioneer100
Shopify Partner
1119 145 481
Click to expand...
 

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

If helpful, Please Like and accept The Solution.
Jaspers
Explorer
52 0 18

Dude just click the eyeball icon like you said and just leave it until you get more products to add.  That way no one sees thge ugly empty shopify squares  untill you click the eyeball / have products too add.

www.JaspersPlus.com