How can I remove empty lines when metafield data is 0?

Solved

How can I remove empty lines when metafield data is 0?

Gumf
Shopify Partner
25 1 1

I am using the following code to display several file downloads saved in custom metafields:

 

<h4 class="accordion-title">{{ product.metafields.custom.downloads }}</h4>
<p class="accordion-panel">
{% unless product.metafields.custom.cad_files.value == blank %}
<u><a target="_blank" rel="noopener noreferrer" href="{{ product.metafields.custom.cad_files.value }}">{{ product.metafields.custom.cad_files_url_title.value }}</a></u>
{% endunless %}
<br>
{% unless product.metafields.custom.specification_guide.value == blank %}
<u><a target="_blank" rel="noopener noreferrer" href="{{ product.metafields.custom.specification_guide.value }}">{{ product.metafields.custom.specification_guide_url_title.value }}</a></u>
{% endunless %}
<br>
{% unless product.metafields.custom.installation_guide.value == blank %}
<u><a target="_blank" rel="noopener noreferrer" href="{{ product.metafields.custom.installation_guide.value }}">{{ product.metafields.custom.installation_guide_url_title.value }}</a></u>
{% endunless %}
<br>
{% unless product.metafields.custom.tech_drawing.value == blank %}
<u><a target="_blank" rel="noopener noreferrer" href="{{ product.metafields.custom.tech_drawing.value }}">{{ product.metafields.custom.tech_drawing_url_title.value }}</a></u>
{% endunless %}
<br>
{% unless product.metafields.custom.trifold_url_download.value == blank %}
<u><a target="_blank" rel="noopener noreferrer" href="{{ product.metafields.custom.trifold_url_download.value }}">{{ product.metafields.custom.trifold_url_title.value }}</a></u>
{% endunless %}
</p>

However, when the value is blank it displays as an empty line. How do I get it to remove the line if the value is returned as 0. Screenshot 2023-09-18 155530.jpg

Accepted Solution (1)

gr_trading
Shopify Partner
1843 145 193

This is an accepted solution.

Hi @Gumf 

 

Wrap your code div and remove the tag br

For any custom development WhatsApp or connect at Email ID: gr.trading15@gmail.com for quick consultation. | Shopify Free codes
To support Buy Me a Coffee

View solution in original post

Replies 3 (3)

Jason
Shopify Partner
11196 226 2287

First step is moving your <br> tag to be within your unless statement. Currently, the break sits outside so will always be rendered.

★ I jump on these forums in my free time to help and share some insights. Not looking to be hired, and not looking for work. http://freakdesign.com.au ★

gr_trading
Shopify Partner
1843 145 193

This is an accepted solution.

Hi @Gumf 

 

Wrap your code div and remove the tag br

For any custom development WhatsApp or connect at Email ID: gr.trading15@gmail.com for quick consultation. | Shopify Free codes
To support Buy Me a Coffee
Gumf
Shopify Partner
25 1 1

Worked perfectly thank you!