This article will cover the use of conditional statements inside html blocks to control dynamic content in your emails.
Want to use complex conditional statements in the drag-and-drop builder? See: Display Conditions in Template Builder.
What is a conditional statement?
A conditional statement begins with an "if" statement do determine if an action should be taken. Conditional statements can be summarized as "if this then that." To review the basics of conditional statements see Advanced Merge Tags and Conditional Statements.
In the examples below colors are used to show html formatting.
This first example shows the conditional statements outside the link element. You can see how the colors show distinct separation between the conditional statement and the html elements. The link destinations are shown in yellow text.
Correct:
This second example shows the conditional statement inside a link element. You can see how the format breaks down quickly and the link URLs are not recognized correctly.
Incorrect:
How Do I Build My HTML for Conditional Links?
Like we learned in the above example, conditional statements are best used outside your actual html elements. You'll notice the proper format is nearly identical to the one used in our first name example:
{% if fname == null or fname == '' %}NO NAME CONTENT{% else %}WITH NAME CONTENT{% endif %}STATIC CONTENT |
You will want to define your primary condition, then build the content to display after. Use {% else %} for your fallback content, and end with {% endif %}. You can learn more about if, else, and other conditional controls here.
Can I See an Example?
Sure! Example code is attached at the bottom of this page. You will find examples for dynamically linked images and dynamically linked buttons. The code is formatted and commented for simple editing, but still requires manual setup.
For assistance with basic HTML editing we recommend the resources on W3schools.
Comments
0 comments
Please sign in to leave a comment.