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

Mustache lint script needs to handle templates that output HTML fragments

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Low Low
    • Integration
    • None

      (Background, linting mustache, for example in moodle-plugin-ci, is done using a custom Moodle script https://github.com/moodlehq/moodle-local_ci/blob/master/mustache_lint/mustache_lint.php.)

      This script does not handle situations like a template which outputs a a <tr> and its content. You get validation errors like:

      .../newresponse.mustache - WARNING: HTML Validation error, line 3:
      Stray start tag “tr”. (d><body><tr class="generaterow" id="qtype-pmatch-new-response_1">
      

      This is because the validator works by rendering the template, and inserting the content into <html><head></head><body> ... template HTML here ... </body></html>. https://github.com/moodlehq/moodle-local_ci/blob/master/mustache_lint/mustache_lint.php#L220.

      In discussion with dobedobedoh in dev chat, we thought that what is needed (both for validation, and for other things like the template library) is an optional extension to the doc comment at the top of our templates. Specific suggestion:

      {{!
          @template core/example
       
          This is am example.
       
          Example context (json):
          {
              "hello": "world"
          }
       
          Test wrapper (html):
          ```
          <table>
          [[templatecontent]]
          </table>
          ```
      }}
      

            Unassigned Unassigned
            timhunt Tim Hunt
            Votes:
            5 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:

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