Hello, community, can you help me to create a email scripting that will show specific email part only to specific criteria, like for example if they are in country of Mexico they can see this email part but if not no content should be visible
Solved! Go to Solution.
Absolutely, you can use the simple conditional statement for that. Here's a Marketo email velocity script that will show a specific email part only to records with Country = Mexico. You can also combine multiple conditions with AND (&&) and OR (||) based on the requirement.
#if ($lead.Country.equals("Mexico"))
<div>This content will be visible to records with Country = Mexico/div>
#else
<div>This content will be displayed to other countries.</div>
#end
Make sure you select the field you're referencing in the velocity script editor from the object tree on the right of the script editor.
you're most of the way there, but you are making it too hard, and you've got a formal reference in the mix that you don't want.
I'd do it like this (let's call this token - my.showMexicoStart):
#set( $COUNTRY_CODE_FILTER = ["mx", "mexico"] )
#set( $country = $lead.Country.toLowerCase()) ## Removed formal reference.
#if(!$COUNTRY_CODE_FILTER.contains($country))
and then a second token (let's call this token - my.showAnythingEnd)
#end
The if statement happily spans two tokens, so you don't need to go through the process of re-evaluating.
You'll also notice that I called the second token a very generic name. You can use this to end ANY of these types of conditional display tokens.
So, the first token goes above all the modules you only want to show to people in Mexico, and the second goes at the end of them.
Cheers
Jo
Absolutely, you can use the simple conditional statement for that. Here's a Marketo email velocity script that will show a specific email part only to records with Country = Mexico. You can also combine multiple conditions with AND (&&) and OR (||) based on the requirement.
#if ($lead.Country.equals("Mexico"))
<div>This content will be visible to records with Country = Mexico/div>
#else
<div>This content will be displayed to other countries.</div>
#end
Make sure you select the field you're referencing in the velocity script editor from the object tree on the right of the script editor.
Hi @shaniala
Another option to @Darshil_Shah1 is that you use dynamic content.
Use segmentation set up by region/country languages, and then you can change the text or image based on the segmentation.
Test and try both ways and see what works best for the company and Marketo instance set-up you have.
Thanks, Zoe
Great suggestion, @Zoe_Forman! Additionally, there's a possibility to even reference the segmentation membership in the velocity, if OP would like to show/hide content based on segment membership via the velocity script as well.
Hi @shaniala - Alteratively to the solutions provided above, You can comment out the module based on some logic like shown below.
1 - Create the below given token. (Make sure to check mark the fields in right pabe which you are going to use in script)
2 - Apply the token above and below of the module like shown in screenshot below.
#set( $COUNTRY_CODE_FILTER = ["mx", "mexico"] )
#set( $country = ${lead.Country.toLowerCase()})
#if(!$COUNTRY_CODE_FILTER.contains($country))
#if( !$inUnsupportedLangList )
#set( $inUnsupportedLangList = true )
<!--
#else
#set( $inUnsupportedLangList = false )
-->
#end
#end
Please let me know if you have any questions on implementation.
you're most of the way there, but you are making it too hard, and you've got a formal reference in the mix that you don't want.
I'd do it like this (let's call this token - my.showMexicoStart):
#set( $COUNTRY_CODE_FILTER = ["mx", "mexico"] )
#set( $country = $lead.Country.toLowerCase()) ## Removed formal reference.
#if(!$COUNTRY_CODE_FILTER.contains($country))
and then a second token (let's call this token - my.showAnythingEnd)
#end
The if statement happily spans two tokens, so you don't need to go through the process of re-evaluating.
You'll also notice that I called the second token a very generic name. You can use this to end ANY of these types of conditional display tokens.
So, the first token goes above all the modules you only want to show to people in Mexico, and the second goes at the end of them.
Cheers
Jo
Thanks @Jo_Pitts1, Thanks for optimizing my code. Your suggestion makes a lot of sense.