1

Is there any js function that will display these notifications that appear on top of the screen? Flash messages use these notifications, but I don't want to use flash messages, I want to display notification without refreshing a page.

2

Craft's JS/UI framework "Garnish" is largely undocumented, but exploring the Craft object it exposes in the console, I found a few methods that might be useful:

// Good for confirmations (blue banners):
Craft.cp.displayNotice('Your changes have been saved.');

// Good for errors (red banners):
Craft.cp.displayError('Uh oh, something bad happened!');

// Custom flash names (for anything else—requires custom CSS):
Craft.cp.displayNotification('custom-flash-key', 'Something very special happened!');

The last one, displayNotification is the abstract method, called by the first two. custom-flash-key gets added to the notification as a classname.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.