Canceling of the template rendering
Copy the link to the article
Copied

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
  • Рекомендации не помогли
  • Нет ответа на мой вопрос
  • Текст трудно понять
  • Не нравится описанный функционал
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.