exit

Immediately terminates script execution. Use this tag to stop processing when a condition is met or an error occurs.

{% if order.cancelled %}
  {% log "Order is cancelled, skipping processing" %}
  {% exit %}
{% endif %}

{% comment %} This code will not run if order is cancelled {% endcomment %}
{% log "Processing order..." %}

Syntax

{% exit %}

Use Cases

Early termination on validation failure:

{% if customer.email == blank %}
  {% log "Customer email is required" %}
  {% exit %}
{% endif %}

{% email to: customer.email, subject: "Welcome!" %}
  <p>Thanks for signing up!</p>
{% endemail %}

Skip processing based on conditions:

Stop after error response:

Conditional processing with multiple checks:

Notes

  • Execution stops immediately when {% exit %} is reached

  • No code after the exit tag will be executed

  • Useful for guard clauses and early returns

  • Does not produce any output

Last updated