Conditional content blocks allow you to show or hide sections of your email based on the value of a recipient variable. Instead of creating multiple separate templates for different audience segments, you build one template with conditional sections that render differently for each recipient.
Why Conditional Content Matters
| Without Conditional Content |
With Conditional Content |
| Separate templates for premium vs free users |
One template — premium section shows only for is_premium = true |
| Separate order confirmation templates for Indian and international customers |
One template — GST details visible only when country = IN |
| Manual segmentation required before each send |
Single API call per recipient — template handles the logic |
Conditional Block Syntax
MigoSMTP uses a Handlebars-inspired conditional syntax within email templates:
Basic If Block
{{#if is_premium}}
<p style="background:#10B981;color:#fff;padding:12px;border-radius:6px;">
🌟 You are a Premium member. Your exclusive 20% discount is already applied.
</p>
{{/if}}
If / Else Block
{{#if is_premium}}
<p>Thanks for being a Premium member, {{first_name}}!
Your dedicated support line is <strong>1800-XXX-XXXX</strong>.</p>
{{else}}
<p>Upgrade to Premium to unlock priority support, advanced analytics,
and unlimited sending. <a href="{{upgrade_url}}">Upgrade Now</a></p>
{{/if}}
Nested Conditions
{{#if has_discount}}
{{#if is_first_order}}
<p>🎉 Welcome! As a first-time customer, you get an extra 10% off.
Use code: <strong>WELCOME10</strong></p>
{{else}}
<p>Your loyalty discount of {{discount_percent}}% has been applied.</p>
{{/if}}
{{/if}}
Supported Conditional Operators
| Operator |
Syntax |
Truthy When |
Example |
| Truthy check |
{{#if variable}} |
Variable is "true", non-empty string, or non-zero number |
{{#if is_premium}} |
| Equality check |
{{#if_eq var "value"}} |
Variable exactly equals the specified string |
{{#if_eq country "IN"}} |
| Not equal |
{{#if_neq var "value"}} |
Variable does not equal the specified string |
{{#if_neq status "cancelled"}} |
| Greater than |
{{#if_gt var 100}} |
Variable (numeric) is greater than the value |
{{#if_gt order_count 5}} |
| Less than |
{{#if_lt var 10}} |
Variable (numeric) is less than the value |
{{#if_lt days_remaining 3}} |
Real-World Conditional Use Cases
| Use Case |
Condition |
What Shows |
| Upsell for free users only |
{{#if_eq plan "free"}} |
Upgrade CTA — hidden for paid users who already have premium |
| GST invoice section |
{{#if_eq country "IN"}} |
GST breakdown table visible only to Indian recipients |
| Free shipping banner |
{{#if_gt order_total 999}} |
"You qualify for free shipping!" banner for orders over ₹999 |
| Urgent trial warning |
{{#if_lt days_remaining 3}} |
Red urgent banner showing when trial has less than 3 days remaining |
| Personalised CTA text |
{{#if is_first_order}} |
"Start Your First Order" vs "Shop Again" for returning customers |
| Referral programme section |
{{#if show_referral}} |
Referral programme block shown only to eligible users |
Best Practices for Conditional Content
- Keep conditions simple — deep nesting (conditions within conditions within conditions) makes templates hard to maintain. If logic is very complex, consider splitting into separate templates.
- Always provide the variable — if a block uses
{{#if is_premium}}, always include is_premium in your API payload (as "true" or "false"). An unprovided variable is treated as falsy — the block is hidden — which may not always be the intended behaviour.
- Test both conditions — when testing, send two test emails: one with the condition truthy, one with it falsy. Verify both render correctly.
- Use else blocks for graceful degradation — whenever you show something to one audience, consider whether the other audience should see an alternative message or simply nothing.
Next Steps