diff --git a/h5p/embed.php b/h5p/embed.php index af236293bea..f62e324b1e3 100644 --- a/h5p/embed.php +++ b/h5p/embed.php @@ -61,15 +61,18 @@ if (empty($messages->error) && empty($messages->exception)) { // Add H5P assets to the page. $h5pplayer->add_assets_to_page(); - // Check if there is some error when adding assets to the page. + // Print page HTML. + echo $OUTPUT->header(); + + // Check if some error has been raised when adding assets to the page. If that's the case, display them above the H5P content. $messages = $h5pplayer->get_messages(); - if (empty($messages->error) && empty($messages->exception)) { - - // Print page HTML. - echo $OUTPUT->header(); - - echo $h5pplayer->output(); + if (!empty($messages->exception) || !empty($messages->error)) { + $messages->h5picon = new \moodle_url('/h5p/pix/icon.svg'); + echo $OUTPUT->render_from_template('core_h5p/h5perror', $messages); } + + // Display the H5P content. + echo $h5pplayer->output(); } else { // If there is any error or exception when creating the player, it should be displayed. $PAGE->set_context(context_system::instance()); @@ -80,12 +83,9 @@ if (empty($messages->error) && empty($messages->exception)) { $PAGE->add_body_class('h5p-embed'); $PAGE->set_pagelayout('embedded'); - // Errors can't be printed yet, because some more errors might been added while preparing the output -} - -if (!empty($messages->error) || !empty($messages->exception)) { - // Print all the errors. echo $OUTPUT->header(); + + // Print all the errors. $messages->h5picon = new \moodle_url('/h5p/pix/icon.svg'); echo $OUTPUT->render_from_template('core_h5p/h5perror', $messages); } diff --git a/h5p/templates/h5perror.mustache b/h5p/templates/h5perror.mustache index 9c0d9d9c313..76107c97b2a 100644 --- a/h5p/templates/h5perror.mustache +++ b/h5p/templates/h5perror.mustache @@ -21,7 +21,7 @@ Variables required for this template: * h5picon - The icon - * message - The error message to display. + * message - The error messages to display. Example context (json): { @@ -33,7 +33,9 @@
- {{#str}}h5p, core_h5p{{/str}} + {{#h5picon}} + {{#str}}h5p, core_h5p{{/str}} + {{/h5picon}}
@@ -42,9 +44,14 @@ {{{ exception }}}
{{/exception}} + {{#info}} + + {{/info}} {{#error}} {{/error}}