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

Enable all emails to be themed, ie add 4 wrapper moustache templates

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide

      Fire of some emails from various sources and confirm they are exactly the same as now. At least trigger some using message api and some that don't.

      Now grab a theme and stick some new templates into it, and fire of some more emails. They should come out like the screen shot attached

      theme/clean/templates/core/email_subject.mustache

      [TEST] {{{subject}}}
      

      theme/clean/templates/core/email_fromname.mustache

      {{{fromname}}} (Test)
      

      theme/clean/templates/core/email_text.mustache

      {{{body}}}
       
      --
       
      Acme Corp is a trade mark of ACME, Inc., and is used under licence. ABN 12 345 555 666.
      Sent to {{{to}}}
      

      theme/clean/templates/core/email_html.mustache

      <body style="background: #eee;">
      <div style="background: #eee;">
       
      <div style="background: white; margin: 5px auto; max-width: 700px; padding: 0 20px; border-radius: 6px; border: 1px solid #ccc;">
      {{{body}}}
      </div>
       
      <div style="text-align: center; font-size:11px; color: #666;">
      <p>Acme Corp is a trade mark of ACME, Inc., and is used under licence. ABN 12 345 555 666.</p>
      <p>Sent to {{{to}}}</p>
       
      <p><a href="support">Support</a> | <a href="privacy">Privacy</a>
      {{#touserid}} | <a href="{{{sitewwwroot}}}/message/edit.php?id={{{touserid}}}">Message preferences</a>{{/touserid}}
      </p>
      </div>
      </div>
      </body>
      

      Additionally also test triggering an email that is only provided with text but no html version. If no template has been provided then nothing should be different. However if a theme template has been provided which adds formatting and branding then the themer would expect this to be used for all emails unless the user has explicitly opted to only have text emails. In this case text only emails are upgraded to html and then have the template applied on top. So test that:

      1) a text only email is send to email_to_user()
      2) a template has been provided
      3) sends an a formatted email
      4) change the users preference to text
      5) resend email and should be text

      Show
      Fire of some emails from various sources and confirm they are exactly the same as now. At least trigger some using message api and some that don't. Now grab a theme and stick some new templates into it, and fire of some more emails. They should come out like the screen shot attached theme/clean/templates/core/email_subject.mustache [TEST] {{{subject}}} theme/clean/templates/core/email_fromname.mustache {{{fromname}}} (Test) theme/clean/templates/core/email_text.mustache {{{body}}}   --   Acme Corp is a trade mark of ACME, Inc., and is used under licence. ABN 12 345 555 666. Sent to {{{to}}} theme/clean/templates/core/email_html.mustache <body style="background: #eee;"> <div style="background: #eee;">   <div style="background: white; margin: 5px auto; max-width: 700px; padding: 0 20px; border-radius: 6px; border: 1px solid #ccc;"> {{{body}}} </div>   <div style="text-align: center; font-size:11px; color: #666;"> <p>Acme Corp is a trade mark of ACME, Inc., and is used under licence. ABN 12 345 555 666.</p> <p>Sent to {{{to}}}</p>   <p><a href="support">Support</a> | <a href="privacy">Privacy</a> {{#touserid}} | <a href="{{{sitewwwroot}}}/message/edit.php?id={{{touserid}}}">Message preferences</a>{{/touserid}} </p> </div> </div> </body> Additionally also test triggering an email that is only provided with text but no html version. If no template has been provided then nothing should be different. However if a theme template has been provided which adds formatting and branding then the themer would expect this to be used for all emails unless the user has explicitly opted to only have text emails. In this case text only emails are upgraded to html and then have the template applied on top. So test that: 1) a text only email is send to email_to_user() 2) a template has been provided 3) sends an a formatted email 4) change the users preference to text 5) resend email and should be text
    • Affected Branches:
      MOODLE_30_STABLE
    • Fixed Branches:
      MOODLE_31_STABLE
    • Pull Master Branch:
      MDL-52990-email-themes

      Description

      This is a follow on from MDL-49682 but extended across the whole system to all emails.

      There needs to be a single generic template which wraps all outgoing emails so that emails can be themed in the same way as anything else. It will take as input the text or html chunk which has already been processed at a deeper level, eg the forum template. The default template would not add anything and it is only intended to be overridden in a theme.

      Some use cases:

      • adding a small footer with the ABN, Cricos number, who the email is directed at, support details, and other guff that corporates, gov, or edu often want or are required to add.
      • adding minimal html header and footer wrapping and css to make the html format much nicer, for instance putting it into a max-width div / table and a bit of inline colour to match the web theme.

      A themer should be able to do all of this easily in 3 templates, one for text email and one for html email, and one for the subject, without touching any of the possible sub-templates (eg the forum template).

      theme/mytheme/templates/core/email_subject.mustache
      theme/mytheme/templates/core/email_text.mustache
      theme/mytheme/templates/core/email_html.mustache

      I'd say this should be implemented near the end of email_to_user but care needs to be taken so that any emails don't get double formatted, ie in MDL-49682 moustache templates the html already has a <head> element (which is empty) which should be removed. So probably a quick audit to make ensure all emails in code or templates are only producing a chunk of html and not a full html document. Or possible email_to_user could parse out any head content and pass that into the generic template which would concat it together with any generic head content?

      ie I'd say a very common subject template would be something like below so that all emails are consistently branded:

      "[{{{siteshortname}}}] {{{subject}}}"
      

        Attachments

        1. screenshot-1.png
          screenshot-1.png
          31 kB
        2. screenshot-2.png
          screenshot-2.png
          32 kB
        3. Selection_774.png
          Selection_774.png
          87 kB

          Issue Links

            Activity

              People

              • Votes:
                1 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  23/May/16