What's your biggest current challenge? Have your say in Community Polls along the right column.

How to hide variables in email template if they contain no data?

Solved

How to hide variables in email template if they contain no data?

RennWelten
Excursionist
29 3 4

Hi everyone!

 

We are using Flow to send order creation triggered internal emails with certain data from the order and its included line items. For some orders those variables can be empty. So my question is how to hide the entire variable output within the mail when no data is available.

 

Example:

Order summary: {{order.name}} <br>
{% for lineItems_item in order.lineItems %}
Quantity: {{lineItems_item.quantity}} <br>
Product: {{lineItems_item.title}} <br>
Variant: {{lineItems_item.variantTitle}} <br>

{% endfor %}

 

Not all products have variants so I'd like to hide the entire line "Variant: ..." if no data exists.

Help would be highly appreciated!

 

Kindest regards

 

Armin

Accepted Solution (1)

DaveMcV
Shopify Staff
104 31 29

This is an accepted solution.

Hi RennWelten,

 

You can try wrapping that line in a `nil` check on the `variant` field, like:

 

{% if lineItems_item.variant != nil %}

Variant: {{lineItems_item.variantTitle}} <br>

{% endif %}

 

Hope that helps!

DaveMcV | Flow Development Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.

View solution in original post

Reply 1 (1)

DaveMcV
Shopify Staff
104 31 29

This is an accepted solution.

Hi RennWelten,

 

You can try wrapping that line in a `nil` check on the `variant` field, like:

 

{% if lineItems_item.variant != nil %}

Variant: {{lineItems_item.variantTitle}} <br>

{% endif %}

 

Hope that helps!

DaveMcV | Flow Development Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.