In my email when the token value is empty or blank, I want to hide a section in my HTML email.
could you please help me with how to achieve this?
Solved! Go to Solution.
No need for the curly braces, and a String field on the Person can never be null
or false
.
To use a field only if it has at least one non-whitespace character, you only need:
#set( $firstName = $lead.FirstName )
#if( $firstName.trim().isEmpty() )
## Do nothing (the section will be hidden)
#else
<div>
<p>Hello $firstName,</p>
</div>
#end
It’s pretty unlikely for all-whitespace, non-empty values to make their way into First Name, but I suppose it’s possible.
Well, “empty” and “blank” are the same thing. You probably meant null which is technically different in the database.
When you say “token”, do you actually mean the value of a Person field? Tokens — for example {{lead.tokens}} — are one way to output database values, but you should think in terms of the database itself. It’s confusing to talk about a token being empty because tokens can output default values even if the database field is empty.
Hi @Muniyandi If you're comfortable using Velocity Scripting (available in Marketo Email Script tokens), you can conditionally display content based on token values.
Example with first Name
#set( $firstName = ${lead.FirstName} )
#if( !$firstName || $firstName.trim() == "" )
## Do nothing (the section will be hidden)
#else
<div>
<p>Hello $firstName,</p>
</div>
#end
Thanks
No need for the curly braces, and a String field on the Person can never be null
or false
.
To use a field only if it has at least one non-whitespace character, you only need:
#set( $firstName = $lead.FirstName )
#if( $firstName.trim().isEmpty() )
## Do nothing (the section will be hidden)
#else
<div>
<p>Hello $firstName,</p>
</div>
#end
It’s pretty unlikely for all-whitespace, non-empty values to make their way into First Name, but I suppose it’s possible.