Hello,
I'm running into a bit of an issue when trying to apply conditionals. when it reaches the else condition, the lead.First Name is left blank when testing the email.
#if ({{lead.First Name:default=Friend}})
Testt
#else
{{lead.First Name}}, Testt
#end
if some one has some pointers, greatly appreciated.
You seem to be mixing together different syntax.
In Velocity, variables (references) are denoted with a $dollarSign or only if proven necessary a ${formalReference} style with a dollar sign + single curly braces.
Your script should look like this:
#if( $lead.FirstName.isEmpty() )
Hi, Friendo!
#else
Hi, ${lead.FirstName}!
#end
Note how I used the formal reference style only in the line that creates output. You shouldn't use it anywhere else.
Hi Sanford,
Thank you for the reply, would I need to set this script into My Tokens? I'm pretty new to Marketo and have tried my best to look over documentation and follow the tutorials. apprecieate the help.
Yes, you'd create an "Email Script" type of {{my.token}} (which is written in Velocity Template Language and also called a "Velocity token").
In the tree of fields on the right-hand side of the Script Editor window, make sure you've checked off FirstName, and any other fields you wish to process in Velocity. If you don't check them off, they aren't present and will always be seen as null.
Then you include the {{my.token}} in your email as with other tokens.
I can't recommend strongly enough that you read my posts on Velocity, both those on the official Products blog and additional posts (not cross-posted here to not overwhelm/overbore people) at https://blog.teknkl.com/tag/velocity.
Finally, when posting code to Community threads, always highlight it using the Advanced Editor's syntax highlighter:
There's no highlighter specific to Velocity, but you can choose Java (not JavaScript) which is intimately related.
Great to hear from you Sanford and thanks for sharing on how to share my code but I don't have that option when replying.
So I modified the script example you suggested and created a token for pretty much each folder directory. I ran a test and was not able to get it to populate. any suggestions why that step I'm missing?
#if( $lead.FirstName.isEmpty() )
Friend,
#else
${lead.FirstName}, Than You!
#end
Here is the token script
and html
Great to hear from you Sanford and thanks for sharing on how to share my code but I don't have that option when replying.
Open the thread, then reply, then click Advanced Editor (this isn't available on mobile).
So I modified the script example you suggested and created a token for pretty much each folder directory.
Please don't do that, you'll just be endlessly confused when your tokens are overridden. You need one token, at the highest possible level in Marketing Activities. Make sure to clear all your redundant tokens out ASAP.
I ran a test and was not able to get it to populate. any suggestions why that step I'm missing?
What did populate in the email, then?
Does your email exist in the Marketing Activities tree under a program/folder that has the {{my.token}} in it?