toast(), toast_container() html()

Notices that show and hide themselves (Bootstrap 5 toasts) in a fixed corner container.

html()->toast($body = '', $extra = [])
html()->toast_container($extra = [])

Options

OptionMeaning
toast($body, $extra)title (escaped), type (success, info, warning, danger), autohide (true), delay (5000 ms), show, no_close, id, class_add, no_escape; the body is developer HTML.
toast_container($extra)toasts (rendered toasts), position (top-end default, top-start, top-center, middle-*, bottom-*), id, class_add.

Example

Welcome

Rendered with the page; it hides after 6 seconds.
This one stays until it is closed.

Two toasts appear in the bottom right corner of the page (Bootstrap 5); Bootstrap 3 shows them as alerts here.

Code

return html()->toast_container([
    'id' => 'docs-ref-toasts',
    'position' => 'bottom-end',
    'toasts' => [
        html()->toast('Rendered with the page; it hides after 6 seconds.', ['title' => 'Welcome', 'delay' => 6000]),
        html()->toast('This one stays until it is closed.', ['type' => 'warning', 'autohide' => false]),
    ],
]) . '<p>Two toasts appear in the bottom right corner of the page (Bootstrap 5); Bootstrap 3 shows them as alerts here.</p>';

Notes

  • The jQuery-free asset yf_bs5_toasts shows them on load and after htmx swaps; _class('htmx')->_toast() adds toasts to an htmx response (htmx toast).
  • $PROJECT_CONF['common']['MESSAGES_AS_TOASTS'] = true turns common()->message_*() into toasts under Bootstrap 5 (default off).
  • One container per corner: two in one corner overlap.

Bootstrap 3 and 5

Bootstrap 3 and 4: alert() boxes in a plain div (title, type, no_close, id, class_add kept).

See also: html/alert, htmx/toast, demo:html/bs5_components