Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-83573

Make course nav drawer templates easier to override

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Won't Do
    • Icon: Minor Minor
    • None
    • 4.2.9, 4.1.15, 4.3.9, 4.4.5, 4.5.1
    • Course
    • MOODLE_401_STABLE, MOODLE_402_STABLE, MOODLE_403_STABLE, MOODLE_404_STABLE, MOODLE_405_STABLE

      Since Moodle 4.0 introduced the navigation drawer for courses it has been very difficult to override the templates it uses. There are two issues that make it hard:

      1. The templates used are hard coded into both renderers and JavaScript
      2. The templates make it so that you need to replace a whole template even if all you want to do is change which templates it calls

      As an example we have a course format that uses sections where the order and number of sections is controlled by an external system because of that we do not want the end user to be able to use drag and drop reordering of sections in the format.

      It is relatively easy to stop this in the main body of the format itself, however in the navigation drawer it requires overriding a rather large amount of code.

      1. you need to do is override the course_index_drawer method in the section render, since the template in there is hardcoded
      2. The override one template in the navigation drawer you need to completely override every template in the route to it, you cannot just override the some parts as you can with the main section templates. See the hardcoded template reference, compared to how it is[ done in the main format templates|https://github.com/moodle/moodle/blob/MOODLE_405_STABLE/course/format/templates/local/content/section.mustache#L103]
      3. You also need to override lots of the JavaScript in the drawer as it also contains hardcoded references to templates, for example the placeholder.js file.
      4. The JavaScript in templates also needs the whole template to be overridden, so it would be good if we could have the JS part of the templates be inside a place holder so we can change it without having to copy the whole template.

      So in summary it would be much easier to override the course nav drawer if:

      1. the presence of a template in a plugins template directory was enough to get it to be used
      2. the templates allowed us to override which templates and JavaScript they called, without changing everything

      So as an example if I in the case of sections it would be nice if my template could look like:

      {{< core_courseformat/local/courseindex/section }}
          {{$ core_courseformat/local/courseindex/section/cm}}
              {{> format_my/courseindex/courseindex/cm }}
          {{/ core_courseformat/local/courseindex/section/cm }}
         {{$ core_courseformat/local/courseindex/section/js}}
              {{#js}}
                   require(['format_my/courseindex/section'], function(component) {
                        component.init('course-index-section-{{id}}');
                  });
              {{/js}}
          {{/ core_courseformat/local/courseindex/section/js}}
      {{/ core_courseformat/local/courseindex/section }}
      

      So that it would potentially be able to make some small changes to them, but still have most core changes come through automatically.

            Unassigned Unassigned
            nmagill Neill Magill
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.