Conditions in Email Templates
  • 13 Sep 2022
  • 1 Minute to read
  • Dark
    Light
  • PDF

Conditions in Email Templates

  • Dark
    Light
  • PDF

Article Summary

Required permissions

An employee must be assigned to the Shop with a Power User role or higher to create and edit templates on a Shop Owner level.

Conditional blocks

To insert a condition in the email template:

  1. Open mail template for editing.
  2. Start the condition by inserting RangeStart: and follow it by the merge field that you want to use as a condition $$Entity.Field$$.
  3. Specify the condition on which the condition body will be shown in the mail:
    • if the condition is not specified, the condition body will be displayed only if there is a value in the merge field used as a condition.
    • check if the field contains a certain text value: RangeStart:$$Entity.Field$$='text'
    • check if the field equals to a certain number: RangeStart:$$Entity.Field$$='0'
  4. Use comment tags <!-- --> to comment the range start merge field and prevent it from rendering on the final document.
  5. Insert the condition body, which will be displayed only if the condition will be met. It could consist of both text and merge fields. Format the merge fields output, if required.
  6. To close the condition, insert the RangeEnd: and follow by the name chosen above and the same condition if any was specified.
  7. Enclose the range end construction in the comment tags.
  8. Proceed with editing the template as usual.
Note

It is not possible to use any comparison operators for the number type merge fields, except for the "equal to" sign =. Or to compare a merge field to another merge field.

For example, here is a condition that will show inner text only if there is a value in the $$Order.CustomerReference$$ merge field:

<!-- RangeStart:$$Order.CustomerReference$$ -->
<p>CustomerReference: $$Order.CustomerReference$$</p>
<!-- $$RangeEnd:$$Order.CustomerReference$$ -->

For numeric type merge fields: inner text will be displayed if the value of the merge field exists and is not zero.

<!-- RangeStart:$$Order.DiscountExVat$$ -->
<p>Discount: $$Order.DiscountExVat$$</p>
<!-- $$RangeEnd:$$Order.DiscountExVat$$ -->

And here is a condition example that will show text only if the merge field value is false:

<!-- RangeStart:$$Order.IsPaid$$='False' -->
<p>Please proceed with the payment</p>
<!-- RangeEnd:$$Order.IsPaid$$='False' -->

Nesting сonditions

Conditional blocks could be nested inside other conditional blocks:

<!-- RangeStart:$$PaymentType.IsPaymentOnInvoice$$='True' -->
<!-- RangeStart:$$Order.TotalDue$$='0.0000' -->
<p>Your Order is fully paid, thank you.</p>
<!-- RangeEnd:$$Order.TotalDue$$='0.0000' -->
<!-- RangeEnd:$$PaymentType.IsPaymentOnInvoice$$='True' -->

And collections could be nested inside conditional blocks as well:

<!-- RangeStart:$$PaymentType.IsPaymentOnInvoice$$='True' -->
<!-- RangeStart:OrderRow-->
<p>$$OrderRow.ProductName$$</p>
<!-- RangeEnd:OrderRow-->
<!-- RangeEnd:$$PaymentType.IsPaymentOnInvoice$$='True' -->