Set and flush global messages
Set a global message
You can set a single message within your PHP code in the current user session. Adding new messages will overwrite any previous ones.
kart()->message('Your message');
Flush/Show a global message
To show and remove (aka flush) the current message a users session you can use code like this.
<?php if ($msg = get('msg', kart()->message())) { ?>
<dialog>
<p><strong>Hi <?= kirby()->user()?->nameOrEmail() ?></strong>,</p>
<p><?= strip_tags(urldecode($msg)) ?></p>
<form method="dialog">
<button autofocus><?= t('close') ?></button>
</form>
</dialog>
<script defer>
// otherwise the ::backdrop pseudo attribute will not work
setTimeout(() => {
document.querySelector('dialog').showModal();
}, 100);
</script>
<?php } ?>