{# A callout, as a macro: components/alert.html (the Python Alert) and any template that warns or informs above or inside a section. {% from "components/_alert.html" import alert %} {{ alert("Past the budget by 12 h", "warning", title="Burn") }} {% call alert(tone="danger", compact=true) %}Two changes clash: see them{% endcall %} message is the body (escaped; pass Markup for intentional HTML), or the caller's block when called with {% call %}. tone is info / success / warning / danger, anything else info. title is a line over the body. icon_name replaces the tone's own icon, whose visually-hidden name says the tone, so the meaning does not rest on colour. dismiss_url adds a close button that POSTs there with the CSRF token. compact is the smaller callout inside a section or a table cell: less padding, the smaller type. Not a live region: it is part of the page, so it would be announced on every load. #} {% macro alert(message=none, tone="info", title=none, icon_name=none, dismiss_url=none, compact=false, id=none, css_class=none) -%} {%- set tone = tone if tone in ("info", "success", "warning", "danger") else "info" -%} {%- set icons = {"info": "info", "success": "check", "warning": "warning", "danger": "error"} -%}
{{ icon(icon_name or icons[tone], size="sm" if compact else none, label=t("alert-" ~ tone)) }}
{%- if title %}

{{ title }}

{% endif %}
{% if caller %}{{ caller() }}{% else %}{{ message }}{% endif %}
{% if dismiss_url %} {# nosemgrep: django-no-csrf-token — Flask app; CSRF is handled by {{ csrf_field() }} below. #}
{{ csrf_field() }}
{% endif %}
{%- endmacro %}