Learn more about DocMergy's If branches
Contact Examples
If
{%if object.firstname%} Hello {{ object.firstname }}! {%else%} Hello there! {%endif%}
What it does:
- {% if object.firstname %}: Checks if the firstname field is set (not blank).
- Hello {{ object.firstname }}!: Displays the first name dynamically, like “Hello Sarah!”
- {% else %}: This is the backup plan — what to show if there's no first name.
- Hello there!: The generic fallback message.
- {% endif %}: Ends the conditional logic.
If Else
{{ get_associated_objects("contact", object.hs_object_id, "deal")[0].dealname }}
{% if get_associated_objects("contact", object.hs_object_id, "deal")[0].dealname %} Associated Deal Name: {{ get_associated_objects("contact", object.hs_object_id, "deal")[0].dealname }} {% else %}No deal name found {% endif %}
- get_associated_objects("contact", object.hs_object_id, "deal"): Pulls a list of deal records linked to this contact.
- [0]: Picks the first deal in that list
- .dealname: Gets the name of that deal.
- If there’s at least one deal, it will show its name.
- If the first associated deal has a name, display it. Otherwise, show ‘No deal name found’.”
- It does two things:
- Checks if the first associated deal exists and has a name.
- If yes, it prints:
"Associated Deal Name: [name]" - If no, it prints:
"No deal name found"
- If yes, it prints:
- Checks if the first associated deal exists and has a name.
If Elif
{% if object.country.value =="New Zealand" %} Kia ora! Looks like you're based in New Zealand {% elif object.country.value == "Australia" %} G'day! You're located in Australia {% endif %}
- {% if object.country.value == "New Zealand" %} : Checks if the country property is set to New Zealand.
- Kia ora! Looks like you're based in New Zealand: Custom message for New Zealand-based contacts. Will show if the country property is set to New Zealand
- {% elif object.country.value == "Australia" %} : If it's not New Zealand, but it is Australia, run this instead. Will show if the country property is set to Australia
- G'day! You're located in Australia: Custom message for Australian contacts.
- {% endif %} Hello, ! Thanks for reaching out to us
- {% if object.firstname == "John" %} : Checks if the firstname property of the contact is exactly John.
- Hello, John! We're happy to assist you today: If John, this message is shown.
- {% elif object.firstname == "Jane" %} : If it wasn't John, it checks if the firstname is Jane.
- Hello, Jane! We’re excited to help you with your inquiry: If Jane, this message is shown.
- {% else %} : If it’s neither John nor Jane, this else block runs.
- Hello, {{ object.firstname }}! Thanks for reaching out to us : For any other name, it shows a generic message using their actual first name.
- {% endif %} : Ends the conditional block.
Deal Examples
Basic If Branch
{% if object.dealname %} Hello! You’re working on the {{object.dealname}} deal. {% endif %}
- {% if object.dealname %} : Check if there is a value for the dealname property on the object (likely a Deal record).
- {{object.dealname}} : Insert the value of the dealname into the message.
- {% endif %} : Close the conditional block
If the deal has a name, then show this message:
-
- ‘Hello! You’re working on the 'deal name' deal.’
If Else Branch{% if object.dealname %} Hello! You’re working on the {{object.dealname}} deal. {% else %} Hello! This deal doesn’t have a name yet. {% endif %}
- If the deal has a name, say 'Hello! You're working on the 'dealname' deal.'
Otherwise, say 'Hello! This deal doesn’t have a name yet - {% if object.dealname %} : Checks if the 'dealname' property exists and is not blank.
- Hello! You’re working on the {{ object.dealname }} deal.: This shows when dealname has a value (e.g., "Website Revamp").
- {% else %} : If the dealname is empty or missing, it runs the next line.
- Hello! This deal doesn’t have a name yet.: A fallback message for when there’s no deal name.
- {% endif %} : Ends the if-else logic.
If Elif Branch
{% if object.dealstage.value == "appointmentscheduled" %} This deal is in the Appointment Scheduled stage {% elif object.dealstage.value == "closedwon" %} This deal has been won! {% endif %}
- If the deal stage is Appointment Scheduled, show a message saying that.
If it's Closed Won, show a message saying the deal has been won.
Otherwise, show nothing - object.dealstage.value: Refers to the internal value of the deal's stage (not the label). These values are often lowercase and don't have spaces — e.g., "appointmentscheduled", "closedwon", etc.
- {% if object.dealstage.value == "appointmentscheduled" %} : Checks if the deal is in the "Appointment Scheduled" stage.
- This deal is in the Appointment Scheduled stage: Message shown if the above condition is true.
- {% elif object.dealstage.value == "closedwon" %} : If it's not "appointmentscheduled", this checks whether the deal has been won.
- This deal has been won!: Message shown if the deal is in the "Closed Won" stage.
- {% endif %} : Closes the conditional logic.
If Elif Else Branch
{% if object.dealstage.value == "appointmentscheduled" %} This deal is in the Appointment Scheduled stage {% elif object.dealstage.value == "closedwon" %} This deal has been won! {% else %} This deal is in a different stage {% endif %}
- This code checks the dealstage of a deal. If it's "Appointment Scheduled," it'll say so. If it's "Closed Won," it shows a different message. If its anything else it will show: This deal is in a different stage
-
object.dealstage.value: This accesses the internal value of the deal's stage — e.g., "appointmentscheduled", "closedwon", etc.
-
{% if object.dealstage.value == "appointmentscheduled" %} : Checks if the deal is currently in the "Appointment Scheduled" stage.
-
{% elif object.dealstage.value == "closedwon" %} : If not in the previous stage, checks if it's been won.
-
{% else %} : If it's neither of the above stages, this block runs.
-
{% endif %} : Closes the conditional logic.