Canceling of the template rendering There can be situation when it is necessary to cancel the template generating. The article describes how to do this. false W3sidGl0bGUiOiJBdXRvbWF0aW9uIiwidXJsIjoiL2RldmVsb3BlcnMvYXV0b21hdGlvbi8ifSx7InRpdGxlIjoiVHdpZy10ZW1wbGF0ZXMiLCJ1cmwiOiIvZGV2ZWxvcGVycy9hdXRvbWF0aW9uL3R3aWcvIn1d Automation /developers/automation/ ["developers","Automation"] ["developers","Automation","Twig-templates"] developers

Canceling of the template rendering

There can be situation when it is necessary to cancel the template generating. The article describes how to do this.

There can be situation when it is necessary to cancel the template generating. For example, it is needed to send the letter with recommended items by trigger, but if there are no reccomendations found for customer, then it is necessary to cancel the template generating and sending. For cancellation you should use {% cancel %} tag.

Example of usage:

{% set recom = best_selling_products() %}
{% if recom|length > 0 %}
  {# displaying recommended items #}
{% else %}
  {% cancel %}
{% endif %}

If template has been cancelled, it will be fixed at action log.

You can specify the message, which will be displayed at action log in tag.

Example of usage with message:

{% set recom = best_selling_products() %}
{% if recom|length > 0 %}
  {# displaying recommended items #}
{% else %}
  {% cancel "Recommended items not found" %}
{% endif %}

In case of cancellation the letter/SMS/printed form template, which are generating manually, user will see the message, specified in {% cancel %} tag.

Thank you for your feedback.
Was this article helpful?
No
  • The recommendations did not help
  • There is no answer to my question
  • The text is difficult to understand
  • I do not like the described functionality
Yes
Previous article
Reference book of available twig-functions
Similarly with filters in templates are available most part of standart functions and some special functions. Full list of available functions you may see in the article.