<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://docs.moodle.org/dev/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Nzn</id>
	<title>MoodleDocs - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://docs.moodle.org/dev/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Nzn"/>
	<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/Special:Contributions/Nzn"/>
	<updated>2026-11-19T01:33:52Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Notifications&amp;diff=52656</id>
		<title>Notifications</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Notifications&amp;diff=52656"/>
		<updated>2017-07-02T07:16:45Z</updated>

		<summary type="html">&lt;p&gt;Nzn: Fixed spelling of &amp;quot;notification&amp;quot; in sample JS code for displaying notifications.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Notifications =&lt;br /&gt;
{{Moodle 3.1}}&lt;br /&gt;
&lt;br /&gt;
New APIs were created around notifications in Moodle 3.1.&lt;br /&gt;
These allow for notifications to be added to the session and subsequently retrieved, either during the current page load, from within the page, or on a later page.&lt;br /&gt;
&lt;br /&gt;
== Adding notifications ==&lt;br /&gt;
The API allows for creation of four types of notification: error, warning, info, and success.&lt;br /&gt;
&lt;br /&gt;
=== Redirect notifications ===&lt;br /&gt;
The typical way of using these notifications is when calling the redirect() function.&lt;br /&gt;
This takes arguments for the target URL, as well as the notification message, and the notification type.&lt;br /&gt;
&lt;br /&gt;
This will likely cover a majority of uses in Moodle.&lt;br /&gt;
    redirect(&#039;/index.php&#039;, &#039;Message on redirect&#039;, null, \core\output\notification::NOTIFY_SUCCESS);&lt;br /&gt;
&lt;br /&gt;
=== Adding other notifications ===&lt;br /&gt;
For those wishing to add notifications outside of a redirect, then the following methods exist for adding notifications:&lt;br /&gt;
&lt;br /&gt;
    // Add a notification of some kind.&lt;br /&gt;
    \core\notification::add($message, $type);&lt;br /&gt;
&lt;br /&gt;
    // Or use the following helper functions:&lt;br /&gt;
    \core\notification::error($message);&lt;br /&gt;
    \core\notification::warning($message);&lt;br /&gt;
    \core\notification::info($message);&lt;br /&gt;
    \core\notification::problem($message);&lt;br /&gt;
&lt;br /&gt;
=== Displaying in-page notifications ===&lt;br /&gt;
It is also possible to display standard notifications from JavaScript after the page has loaded.&lt;br /&gt;
&lt;br /&gt;
This can be achieved using the core/notification AMD module&#039;s addNotificiation(), or addNotifications functions.&lt;br /&gt;
&lt;br /&gt;
Notifications added in this way are &#039;&#039;not&#039;&#039; added to the session. They are only displayed immediately on the page.&lt;br /&gt;
    require([&#039;core/notification&#039;], function(notification) {&lt;br /&gt;
      notification.addNotification({&lt;br /&gt;
        message: &amp;quot;Your message here&amp;quot;,&lt;br /&gt;
        type: &amp;quot;info&amp;quot;&lt;br /&gt;
      });&lt;br /&gt;
&lt;br /&gt;
      notification.addNotifications([&lt;br /&gt;
        {&lt;br /&gt;
          message: &amp;quot;Your notification here&amp;quot;,&lt;br /&gt;
          type: &amp;quot;info&amp;quot;&lt;br /&gt;
        },&lt;br /&gt;
        {&lt;br /&gt;
          message: &amp;quot;Your second notification here&amp;quot;,&lt;br /&gt;
          type: &amp;quot;success&amp;quot;&lt;br /&gt;
        }&lt;br /&gt;
      ]);&lt;br /&gt;
    });&lt;br /&gt;
&lt;br /&gt;
== Rendering notifications ==&lt;br /&gt;
Notifications are usually rendered automatically at the following times:&lt;br /&gt;
* If notifications are added after the page heading, but before the footer, these are immediately output;&lt;br /&gt;
* If notifications are added after the page footer, these are stored in the session until fetched at a later time; and&lt;br /&gt;
* If notifications are added before the page heading starts, they are automatically fetched and rendered during render of the page heading (e.g. $OUTPUT-&amp;gt;heading()). This includes those stored in the session from a previous page load.&lt;br /&gt;
&lt;br /&gt;
Notifications can also be fetched using the core/notification AMD module&#039;s fetchNotifications() function.&lt;br /&gt;
&lt;br /&gt;
This is called as standard by a web service shortly after page load.&lt;/div&gt;</summary>
		<author><name>Nzn</name></author>
	</entry>
</feed>