We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Show/Hide Overlay Text On Collection pages if there is an image present - Debut Theme

Show/Hide Overlay Text On Collection pages if there is an image present - Debut Theme

Swaggerlikeme
Excursionist
47 0 3

Hi i would like to be able to check if there is an image for the collection and if there is then show the image on collection pages and hide the overlay text. Any ideas how this can be achieved. 

the image below has the overlay. Because there is an image i don't need to have the text overlay in this case. but when there is no image for the said collecto  then it should show the overlay/title. 

Swaggerlikeme_0-1707344263683.png

 

Replies 4 (4)

Swaggerlikeme
Excursionist
47 0 3
<noscript>
          <div class="collection-hero__image" style="background-image: url({{ collection.image | img_url: '2048x600', crop: 'top' }});"></div>
        </noscript>
        <div class="collection-hero__title-wrapper">
          <h1 class="collection-hero__title page-width">
              <span class="visually-hidden">{{ 'collections.general.collection_label' | t }}: </span>
              {{ collection.title }}
          </h1>
        </div>

HI community,  This code is from  collection-template.liquid. If would like to hide {{collection.title}} if there is a background image present. If there is no background image then i would like to show it. Can this be done with an if statement?

 

thanks

RJ

Swaggerlikeme
Excursionist
47 0 3

I tried this code and it worked. Is there anything wrong with doing it this way? Would it have any sort of negative impact on performance etc. 

 

<noscript>
          <div class="collection-hero__image" style="background-image: url({{ collection.image | img_url: '2048x600', crop: 'top' }});"></div>
        </noscript>
        <div class="collection-hero__title-wrapper">
          <h1 class="collection-hero__title page-width">
              <span class="visually-hidden">{{ 'collections.general.collection_label' | t }}: </span>
            {%  unless collection.image %}
              {{ collection.title }}
            {% endunless %} 
          </h1>
        </div>
ShirleyE
Visitor
2 0 1

Have you noticed any negatives? I have this exact same question and can't find a solution anywhere!

Swaggerlikeme
Excursionist
47 0 3

Hi shirley, 

 

It works fine for me and i have not found any issue. 

 

thanks

RJ