Flash
Flash — one-time UI messages persisted in the session across redirects.
Flash messages are stored in the session under the key "_flash" as a pipe-separated list of "key\x01value" entries. They are loaded into conn assigns at the start of each request by the session middleware, and consumed (cleared) when they are rendered by Form.Flash.render or Flash.loaded_flashes/1.
Typical usage:
conn
|> Flash.put("info", "Account created. Please confirm your email.")
|> redirect_to("/login")In a .march.html layout:
<.Form.FlashGroup conn={conn} />Built-in flash keys and their ARIA roles:
"info" → role="status" (polite, non-interruptive)
"error" → role="alert" (assertive)
"warning" → role="alert"Custom keys are rendered with class "flash-{key}" and role="status".
Functions
Remove all flash messages from the session.
Called automatically after Form.FlashGroup renders so messages
are not shown again on the next page.Remove the flash message for a single key.
Read a flash message for key without consuming it.
Returns None if no flash is set for this key.
Flash.get(conn, "info") -- Some("Profile updated.") or NoneReturn all pending flash messages as a list of (key, message) pairs.
Does not consume the flash — call clear/1 explicitly if needed,
or use Form.FlashGroup which renders and clears in one step.Store a flash message for key in the conn session.
Replaces any existing message for the same key — only one message
per key is stored at a time.
conn |> Flash.put("info", "Profile updated.")
conn |> Flash.put("error", "Something went wrong.")Render a single flash message as an HTML string.
Public so callers can render individual messages outside the group.