Uploaded image for project: 'Moodle Community Sites'
  1. Moodle Community Sites
  2. MDLSITE-6065

Clarify rules for JavaScript in mustache template


    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Low Low
    • Coding style
    • None

      I recently had to fix my block_workflow plugin which was using M.core.init_formautosubmit (which seems to have been removed without following the proper deprecation process, but that is beside the point). https://github.com/moodleou/moodle-block_workflow/blob/18cdeb5fad00b4eaf078bf5d23e7c82894601ff8/yui/src/comments/js/comments.js#L233

      The problem is that, when I tried to find the new equivalent function to M.core.init_formautosubmit, it did not exist. The code was now inline in https://github.com/moodle/moodle/blob/master/lib/templates/single_select.mustache#L119. Therefore, I was force to copy and paste the logic.

      (Of course, I could completely rewrite the Ajax parts of my plugin to use templates, but that is not happening right now.)

      Anyway, I always assumed that the only JS you should have in a template is simple calles to initialise code that is in a an AMD module, like https://github.com/moodle/moodle/blob/master/lib/form/templates/element-advcheckbox-inline.mustache#L34.

      However, clearly some people disagree (e.g. https://github.com/moodle/moodle/blob/master/calendar/templates/upcoming_mini.mustache#L62). Having discussed this with dobedobedoh I am creating this issue so we can decide what the coding standard should be.

            Unassigned Unassigned
            timhunt Tim Hunt
            2 Vote for this issue
            2 Start watching this issue


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