You are here

htmlmail.html.twig in HTML Mail 8

Same filename and directory in other branches
  1. 8.3 templates/htmlmail.html.twig

Default template for HTML Mail.

DO NOT EDIT THIS FILE. Copy it to your theme directory, and edit the copy.

========================================================= Begin instructions.

When formatting an email message with a given $module and $key, [1]HTML Mail will use the first template file it finds from the following list: 1. htmlmail--$module--$key.html.twig 2. htmlmail--$module.html.twig 3. htmlmail.html.twig

For each filename, [2]HTML Mail looks first in the chosen Email theme directory, then in its own module directory, before proceeding to the next filename.

For example, if example_module sends mail with: drupal_mail("example_module", "outgoing_message" ...)

the possible template file names would be: 1. htmlmail--example_module--outgoing_message.html.twig 2. htmlmail--example_module.html.twig 3. htmlmail.html.twig

Template files are cached, so remember to clear the cache by visiting admin/config/development/performance after changing any .html.twig files.

The following variables available in this template:

message.body The message body text.

message.module The first argument to [3]drupal_mail(), which is, by convention, the machine-readable name of the sending module.

message.key The second argument to [4]drupal_mail(), which should give some indication of why this email is being sent.

message.message_id The email message id, which should be equal to "{$module}_{$key}".

message.headers An array of email (name => value) pairs.

message.from The configured sender address.

message.to The recipient email address.

message.subject The message subject line.

message.body The formatted message body.

message.language The language code for this message.

message.params Any module-specific parameters.

template_name The basename of the active template.

template_path The relative path to the template directory.

template_url The absolute URL to the template directory.

theme The name of the Email theme used to hold template files. If the [5]Echo module is enabled this theme will also be used to transform the message body into a fully-themed webpage.

theme_path The relative path to the selected Email theme directory.

theme_url The absolute URL to the selected Email theme directory.

debug TRUE to add some useful debugging info to the bottom of the message.

Other modules may also add or modify theme variables by implementing a MODULENAME_preprocess_htmlmail(&$variables) [6]hook function.

References

1. http://drupal.org/project/htmlmail 2. https://www.drupal.org/documentation/theme 3. https://www.drupal.org/developing/api/8/render 4. http://drupal.org/project/echo

=========================================================== End instructions.

File

templates/htmlmail.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Default template for HTML Mail.
  5. *
  6. * DO NOT EDIT THIS FILE. Copy it to your theme directory, and edit the copy.
  7. *
  8. * ========================================================= Begin instructions.
  9. *
  10. * When formatting an email message with a given $module and $key, [1]HTML
  11. * Mail will use the first template file it finds from the following list:
  12. * 1. htmlmail--$module--$key.html.twig
  13. * 2. htmlmail--$module.html.twig
  14. * 3. htmlmail.html.twig
  15. *
  16. * For each filename, [2]HTML Mail looks first in the chosen Email theme
  17. * directory, then in its own module directory, before proceeding to the
  18. * next filename.
  19. *
  20. * For example, if example_module sends mail with:
  21. * drupal_mail("example_module", "outgoing_message" ...)
  22. *
  23. *
  24. * the possible template file names would be:
  25. * 1. htmlmail--example_module--outgoing_message.html.twig
  26. * 2. htmlmail--example_module.html.twig
  27. * 3. htmlmail.html.twig
  28. *
  29. * Template files are cached, so remember to clear the cache by visiting
  30. * admin/config/development/performance after changing any .html.twig files.
  31. *
  32. * The following variables available in this template:
  33. *
  34. * message.body
  35. * The message body text.
  36. *
  37. * message.module
  38. * The first argument to [3]drupal_mail(), which is, by convention,
  39. * the machine-readable name of the sending module.
  40. *
  41. * message.key
  42. * The second argument to [4]drupal_mail(), which should give some
  43. * indication of why this email is being sent.
  44. *
  45. * message.message_id
  46. * The email message id, which should be equal to
  47. * "{$module}_{$key}".
  48. *
  49. * message.headers
  50. * An array of email (name => value) pairs.
  51. *
  52. * message.from
  53. * The configured sender address.
  54. *
  55. * message.to
  56. * The recipient email address.
  57. *
  58. * message.subject
  59. * The message subject line.
  60. *
  61. * message.body
  62. * The formatted message body.
  63. *
  64. * message.language
  65. * The language code for this message.
  66. *
  67. * message.params
  68. * Any module-specific parameters.
  69. *
  70. * template_name
  71. * The basename of the active template.
  72. *
  73. * template_path
  74. * The relative path to the template directory.
  75. *
  76. * template_url
  77. * The absolute URL to the template directory.
  78. *
  79. * theme
  80. * The name of the Email theme used to hold template files. If the
  81. * [5]Echo module is enabled this theme will also be used to
  82. * transform the message body into a fully-themed webpage.
  83. *
  84. * theme_path
  85. * The relative path to the selected Email theme directory.
  86. *
  87. * theme_url
  88. * The absolute URL to the selected Email theme directory.
  89. *
  90. * debug
  91. * TRUE to add some useful debugging info to the bottom of the
  92. * message.
  93. *
  94. * Other modules may also add or modify theme variables by implementing a
  95. * MODULENAME_preprocess_htmlmail(&$variables) [6]hook function.
  96. *
  97. * References
  98. *
  99. * 1. http://drupal.org/project/htmlmail
  100. * 2. https://www.drupal.org/documentation/theme
  101. * 3. https://www.drupal.org/developing/api/8/render
  102. * 4. http://drupal.org/project/echo
  103. *
  104. * =========================================================== End instructions.
  105. */
  106. #}
  107. <div class="htmlmail-body">
  108. {{ message.body }}
  109. </div>
  110. {% if debug %}
  111. <hr />
  112. <div class="htmlmail-debug">
  113. <dl>
  114. <dt>
  115. <p>To customize this message:</p>
  116. </dt>
  117. <dd>
  118. <ol>
  119. {% if not theme %}
  120. <li>
  121. <p>
  122. Visit <u>admin/config/system/htmlmail</u> and select a theme to hold your custom email template files.
  123. </p>
  124. </li>
  125. {% elseif not theme_path %}
  126. <li>
  127. <p>
  128. Visit <u>admin/appearance</u> to enable your selected <u>{{ theme|capitalize }}</u> theme.
  129. </p>
  130. </li>
  131. {% endif %}
  132. {% set themeTemplate = "%s/%s"|format(theme_path, message_template) %}
  133. {% if _self.getTemplateName() == themeTemplate %}
  134. <li>
  135. <p>
  136. Edit your<br />
  137. <code>
  138. {{ _self.getTemplateName() }}
  139. </code>
  140. <br />file.
  141. </p>
  142. </li>
  143. {% endif %}
  144. {% if not theme_html_exists %}
  145. <li>
  146. <p>
  147. Copy<br />
  148. <code>{{ module_path }}/htmlmail.html.twig</code>
  149. <br />to<br />
  150. <code>{{ theme_path }}/htmlmail.html.twig</code>
  151. </p>
  152. </li>
  153. {% endif %}
  154. {% if not module_template_exists %}
  155. <li>
  156. <p>
  157. For module-specific customization, copy<br />
  158. <code>{{ module_path }}/htmlmail.html.twig</code>
  159. <br />to<br />
  160. <code>{{ theme_path }}/{{ module_template }}</code>
  161. </p>
  162. </li>
  163. {% endif %}
  164. {% if not message_template_exists %}
  165. <li>
  166. <p>
  167. For message-specific customization, copy<br />
  168. <code>{{ module_path }}/htmlmail.html.twig</code>
  169. <br />to<br />
  170. <code>{{ theme_path }}/{{ message_template }}</code>
  171. </p>
  172. </li>
  173. {% endif %}
  174. <li>
  175. <p>
  176. Edit the copied file.
  177. </p>
  178. </li>
  179. <li>
  180. <p>
  181. Send a test message to make sure your customizations worked.
  182. </p>
  183. </li>
  184. <li>
  185. <p>
  186. If you think your customizations would be of use to others,
  187. please contribute your file as a feature request in the
  188. <a href="http://drupal.org/node/add/project-issue/htmlmail">issue queue</a>.
  189. </p>
  190. </li>
  191. </ol>
  192. </dd>
  193. {% if message.params %}
  194. <dt>
  195. <p>
  196. The {{ message.module }} module sets the <u><code>message.params</code></u>
  197. variable. For this message,
  198. </p>
  199. </dt>
  200. <dd>
  201. <p>
  202. <code>
  203. <pre>
  204. $params = {{ pre_formatted_params }}
  205. </pre>
  206. </code>
  207. </p>
  208. </dd>
  209. {% endif %}
  210. </dl>
  211. </div>
  212. {% endif %}