Enable Section if Specific Collection is Not Empty

I think someone should be able to solve this pretty quickly.

I created a collection titled SALE. It only populates when i am running a sale and i tag discounted products with SALE.

I have an announcement bar section i created that links to the collection page. My theme code layout is below.

I want to show the first announcement when SALE collection contains products and hide the normal announcement. When sale collection does not contain products, i want to hide the sale and show the normal. Any ideas?


      {% section 'announcement_sale' %}
      {% section 'announcement' %}
      {% section 'header' %}
1 Like

Hi @DavidCab ,

Please modify your code like below. The code will call the sale collections, and if the number of product is above zero, then it will show the “announcement_sale.” If it is not, it will show the “announcement”


{% if  collections["sale"].products.size > 0 %}
      {% section 'announcement_sale' %}
{% else %}
      {% section 'announcement' %}
{% endif %}
      {% section 'header' %}