I have a set of Tokens containing CONTRACT NUMBERS and I'm trying to get the lead's Contract Number to simply display for one of them, but I keep getting a blank display in the email test. I tried setting a variable and assigning it the first Contract Number value. I then, wanted to check if the field is blank, and if so show nothing, then if the field contains data, i wanted the value to display. I'm not sure if there are errors with my syntax structure as this my first time writing this script. I've supplied the example below, and am welcome to any suggestions.
#set($contractNum1 = $lead.titledVehicleContractNumber1)
##Titled Vehicle Contract Number 01
#if($lead.titledVehicleContractNumber1.isEmpty())
##Show Nothing
#else
$contractNum1.equals($lead.titledVehicleContractNumber1)
#end
${contractNum1}
Can you please use the syntax highlighter ("Insert/Edit Code Sample") so your code is readable? Then we'll continue.
OK, I edited your post for you, but please use the highlighter next time.
Anyway, much as I love Velocity, don’t actually understand why you’re using it here. “Print the field value if it’s not empty, otherwise don’t print anything” is how regular old {{lead.tokens}} work. {{lead.Titled Vehicle Contract Number 1}} is all you need.
@hcoleman please return to your thread and check responses.
Hi,
Thank you for getting back to my question.
What I'm trying to achieve is to display a list of VIN numbers, but I starting with one line of data at a time. The logic is meant to display data if the field has a value and to not display if the field doesn't not have a value. I had to approach it a bit different the second time around.
##Test Contract Number 01
#if(!$lead.titledVehicleContractNumber1)
## Do nothing (hides section)
#else
Your content here: $lead.titledVehicleContractNumber1
#end
${$lead.titledVehicleContractNumber1}
When testing the section of the email containing the my.token, it would end up blank, until I placed the ${ } after the conditional statement. I'm trying to get the script the successfully print to the screen, but it's not working. I am still very new to velocity script and how tokens work, but I'm trying to explore and learn how it works properly.
Again, are you just trying to output *the value of the field*, as long as it's not empty?
Or some other value as well/instead, which you want to suppress completely if the field is empty?
Correct, I'm trying to display the value of the field entirely, if it contains data. Once I get the script to work, the plan is to repeat the script 20 times to display all of the possible Contract Numbers currently owned by the customer. I'm sure there is a more efficient way of displaying all of the contract numbers, but I was starting out small, and the reason we didn't want to just place the tokens directly in the email is to avoid all of the extra spaces generated from the tokens with empty values.
I'm not sure if my syntax is correct. Any suggestions?
the reason we didn't want to just place the tokens directly in the email is to avoid all of the extra spaces generated from the tokens with empty values.
But there aren’t any spaces “generated from the tokens with empty values.” If a field is empty, the corresponding {{lead.token}} generates nothing at all.
It seems like you’re actually outputting something else, like I asked here:
Again, are you just trying to output *the value of the field*, as long as it's not empty?
Or some other value as well/instead, which you want to suppress completely if the field is empty?
That “something else” can be as simple as a <br>
tag, or a wrapper <div>
or <p>
. If you type this in a Rich Text box, hitting Enter for a new line:
{{lead.Token 1}}
{{lead.Token 2}}
And Marketo implements that line break via a wrapper <div>
:
Then when the values are empty, the token output will also be empty. But the rendered HTML will have a couple of raw line breaks (note the height of the <div>
is still 0 by default, though any number of styles can change that):
<div>
</div>
<div>
</div>
Those line breaks aren’t from the token, however. They’re from the way the <div>
is rendered.
Now if you want no <div>
at all if the token turns out to be empty, you do indeed need Velocity. But you’re overcomplicating it, it’s just like this:
#if( !$lead.SomeField.isEmpty() )
<div>${lead.SomeField}</div>##
#end
The trailing ##
removes even the line break from the output, so you can get the <div>
s right next to each other with no whitespace.