Skip to main content

Notification

Moodle notifications

Available
Needs review

Description

Notifications are coupled with actions and provide instant feedback to the action results. Moodle notifications are shown right above the actionable content or overlaying the user interface for JavaScript related actions.

Source files

  • lib/amd/src/notification.js
  • lib/templates/notification_info.mustache
  • lib/templates/notification_success.mustache
  • lib/templates/notification_warning.mustache
  • lib/templates/notification_error.mustache

Core renderer

Notifications can be added in PHP using the core renderer notification method

<?php 
  $OUTPUT->notification('message', 'info');
 ?>

Notification templates

core/notification_info
core/notification_success
core/notification_warning
core/notification_error

JavaScript Notifications

<button class="btn btn-default" data-action="shownotification">Show JS Notification</button>
{{#js}}
require(
[
    'jquery',
    'core/notification'
],
function(
    $,
    Notification
) {
    $('[data-action="shownotification"]').on('click', function() {
      Notification.alert('Notification message', 'Extra content for notification message');
    });
});
{{/js}}