<p>Craft's JS/UI framework &quot;Garnish&quot; is largely undocumented, but exploring the <code>Craft</code> object it exposes in the console, I found a few methods that might be useful:</p>
<pre class="lang-js prettyprint-override"><code>// 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!');
</code></pre>
<p>The last one, <code>displayNotification</code> is the abstract method, called by the first two. <code>custom-flash-key</code> gets added to the notification as a classname.</p>

CC BY-SA 4.0
2022-12-02T20:40:25.840Z
How could these be set from a module?
Augustine Calvino
CC BY-SA 4.0
2023-01-16T16:59:02.353Z
how to do this with craft 4?
tenshi
CC BY-SA 4.0
2023-01-19T17:52:01.263Z
@AugustineCalvino Generally speaking, flashes set from the back-end (i.e. a controller) should go through `Craft::$app->getSession()->setNotice($message)` and `->setError($message)`. Craft will automatically render those notifications for you when the page loads!
August Miller
CC BY-SA 4.0
2023-01-19T20:19:02.500Z
@tenshi This still applies to Craft 4. 4.2.0 introduced rich notifications, which means these JavaScript methods now support additional arguments—haven't had a chance to document this, yet, though!
August Miller
CC BY-SA 4.0
2020-11-22T23:23:37.277Z
2020-11-22T23:23:37.277Z
August Miller
<p>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.</p>

<control-panel>
Displaying notification in control panel
# Displaying notification in control panel

(Asked by: username_0 on 2020-11-22)

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.

**Tags:** control-panel


---

## 1 answers

### Answer by username_1 on 2020-11-22. Score: 5 | Accepted answer

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.

> **Comments:**
> **username_2**: How could these be set from a module?  
> **username_3**: how to do this with craft 4?  
> **username_1**: @AugustineCalvino Generally speaking, flashes set from the back-end (i.e. a controller) should go through `Craft::$app->getSession()->setNotice($message)` and `->setError($message)`. Craft will automatically render those notifications for you when the page loads!  
> **username_1**: @username_3 This still applies to Craft 4. 4.2.0 introduced rich notifications, which means these JavaScript methods now support additional arguments—haven't had a chance to document this, yet, though!  

---

