Allow 'IF' statements on Merge Fields in Communication Triggers
Completed
When producing communication trigger templates, all required fields have to be included; we have many of these under specific headings (for example 'What To Bring'.
This looks similar to:
<h2>What to bring</h2>
{{ delegate.event.course.course_text_11 }}
If 'what to bring' is empty on the course template, the heading of course still shows up. It would be helpful to have some sort of 'if value exists, print' function, similar to:
{{ if $delegate.event.course.course_text_11 ne }}
<h2>What to bring</h2>
{{ delegate.event.course.course_text_11 }}
{{ /if }}
So we can produce 'dynamic' e-mails, that only include values which are present.
-
The communication templates use a python based engine called Jinja.
You can do some complex arguments within including IF statements. Here's one such example which varies the content based on the number of active students registered to the event:
{% set glob={"delegate_sum":0} %}
{% for student in delegate.event.active_students %}{% set _ = glob.update({"delegate_sum": glob.delegate_sum + student.delegates_num | string | int }) %}
{% set delegate_sum = glob.delegate_sum %}
{% if delegate_sum >= 5 %}
There are >= 5 students. The delegate_sum = {{ delegate_sum }}
{% elif delegate_sum >= 3 %}
There are >= 3, but less than 5 students. The delegate_sum = {{ delegate_sum }}
{% else %}
There are < 3 students. The delegate_sum = {{ delegate_sum }}
{% endif %}
The 'elif' function should be what you're looking for here.
Please sign in to leave a comment.
Comments
2 comments