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

Topic summary

A user encountered an issue where empty lines appeared in their HTML output when metafield values were blank or returned as 0, despite using {% unless %} statements to conditionally display file download links.

Problem: The <br> tags were positioned outside the conditional blocks, causing them to render even when metafield data was empty.

Solution provided:

  • Move <br> tags inside the {% unless %} statements so they only render when content exists
  • Alternatively, wrap the entire code block in a <div> and remove standalone <br> tags

Outcome: The original poster confirmed the solution worked perfectly, resolving the empty line display issue.

Summarized with AI on November 16. AI used: claude-sonnet-4-5-20250929.

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.

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

Hi @Gumf

Wrap your code div and remove the tag br

Worked perfectly thank you!