Display alert notification in the panel

Hello,

I try to display an alert notification in the panel on the hook “panel.site.update”

So I have just started with this simple code in a plugin file:

kirby()->hook(['panel.site.update'], function( $site , $oldSite ) {
  panel()->alert("Error!!");
});

… but the alert didn’t appear when I change a panel options field value and save.
I’ve got the green smile instead.

If I replace

panel()->alert("Error!!");

by …

echo "Error!!";
die();

The hook catch my message.

notify() or alert() don’t work if you don’t redirect.

kirby()->hook(['panel.page.update'], function($page) {
  panel()->alert("Error!!");
  panel()->redirect($page);
});

Thanks. Works with the redirect now :slight_smile:

If I need to translate the alert message, may I have access to the l::get() value in the hook?

The language variables are not available in the config. but you could probably load them manually in a hook like in a route, as described here: AJAX Mail Translation problem

Is there a way to show an alert in the panel in Kirby3 ?

2 Likes

Hi @piaaaac,

I would like to know if you find a solution to show an alert in the panel? I didn’t find a good way to handle them.

Thanks.

That was ages ago… but no, I didn’t, I’m sorry

1 Like