How to hide table rows in an email when the token is empty

Highlighted
Level 2

How to hide table rows in an email when the token is empty

Does anyone know how to hide a row in a table when the value in the data is zero/empty.

I need to hide the tokens when the field value is blank so that the table resizes. Can anyone help with this?

Many thanks in advance.

5 REPLIES 5
Highlighted
Level 10 - Community Moderator

Re: How to hide table rows in an email when the token is empty

This is only possible if you're outputting all or part of the table from Velocity.

 

If you are, then it's as simple as

#if( !$lead.YourFieldName.isEmpty() )
<tr><td>This entire table row will only be included if the field has a value</td></tr>
#end

 

Highlighted
Level 2

Re: How to hide table rows in an email when the token is empty

Thank you. 

Highlighted
Level 2

Re: How to hide table rows in an email when the token is empty

Hi there,

Is it at all possible to give me a little more assistance with collapsing empty rows/cells in a Marketo table if there is no data feed into it from underlying source.

I've never used Velocity scripting. 

 

Is there any other way or documentation I can read to achieve this?

I really appreciate any help you may be able to give me.

Kind regards,

Kirstie

Highlighted
Level 10 - Community Moderator

Re: How to hide table rows in an email when the token is empty

The snippet above is about as easy as Velocity gets!

 

Simply create a new Velocity ("Email Script") {{my.token}}, check off and drag your field from the right-hand side of Script Editor, and substitute it in code like the above.

 

You should also read this post: https://blog.teknkl.com/strive-to-avoid-velocity-formal-references/

Highlighted
Level 5

Re: How to hide table rows in an email when the token is empty

@Kirstie_Olah ,

by way of explanation of @SanfordWhiteman 's code

 

#if( !$lead.YourFieldName.isEmpty() )
<tr><td>This entire table row will only be included if the field has a value</td></tr>
#end

 

 

#if( !$lead.YourFieldName.isEmpty() )

This line is a conditional if statement that tests to see whether the field in question (Sanford has used a dummy field name, so substitute 'YourFieldName' with the correct field name (e.ge. sixMonthSpend).  the ! is a logical NOT.  So, this entire line can be read as if lead.YourFieldName is not empty then do what is inside the if statement.

 

<tr><td>This entire table row will only be included if the field has a value</td></tr>

This is the HTML output that goes into your email.  This only gets executed if the field you are testing above is NOT empty.

 

#end

This ends the if statement.  You can have multiple lines between the #if and the #end.  

 

You might need to do multiple tests, and potentially hide an entire table, or just some rows.

 

An example might be if you have threeMonthSpend and sixMonthSpend (you need to read up on logical ands and logical ors in velocity).  If both were empty, you'd not show the spend table at all, but maybe output some text that says 'give us money'.  However, if either has a value, then you'd output the header row of the table (maybe with two columns - 'Period' and 'Spend').   

You'd then test each of the fields as per Sanford's code above, and output the row based on the values stored in each field.

I have no idea if I've helped or confused you even more 🙂

Cheers

Jo