This article will cover the use of conditional statements inside HTML blocks to control dynamic content in your emails.
What is a Conditional Statement?
How to Build HTML for Conditional Links
Want to use complex conditional statements in the Drag and Drop Email Builder? See Display Conditions in Template Builder.
What is a Conditional Statement?
A conditional statement begins with an "if" statement to 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 Insert Link elements. You can see the distinct separation between the conditional statement and the link HTML elements. The link destinations are shown in yellow text.
Correct:
This second example shows the conditional statement inside an Insert Link element. With this format, the conditional statement would not be recognized.
Incorrect:
How to Build HTML for Conditional Links
Like we learned in the above example, conditional statements are best used outside your the Insert Link html elements.
{% 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.
Example Code
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
1 comment
yes
Please sign in to leave a comment.