Removing custom fields if they are empty


A client of mine sends emails which list the content of a couple of custom fields, e.g.

<< Custom field 1>>
<< Custom field 2>>
<< Custom field 3>>
<< Custom field 4>>

In the HTML each field is wrapped in a <p> tag to ensure it is on a new line.

My question is, if for example <<Custom field 2>> is empty is there anyway to get the email to remove the line altogether so it reads

<< Custom field 1>>
<< Custom field 3>>
<< Custom field 4>>

With no gap between 3 and 4.

Word quite happily does this in Mail Merge, removing fields that are empty within envelopes.

Any help much appreciated.


davidaf davidaf, 6 years ago


There's no built in way to do this, unfortunately. However, I did test this code:

<p>Record A</p>
<p>Record B</p>
<p>Record C</p>

And all the email clients actually ignored the empty paragraph tags and displayed no gap. You may just be able to leave it like that.

The Campaign Monitor Blog – HTML email smarts to go with your good looks

Join 200,000 companies around the world that use Campaign Monitor to run email marketing campaigns that deliver results for their business.

Get started for free