You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. # Templates
  2. Synapse uses parametrised templates to generate the content of emails it sends and
  3. webpages it shows to users.
  4. By default, Synapse will use the templates listed [here](https://github.com/matrix-org/synapse/tree/master/synapse/res/templates).
  5. Server admins can configure an additional directory for Synapse to look for templates
  6. in, allowing them to specify custom templates:
  7. ```yaml
  8. templates:
  9. custom_template_directory: /path/to/custom/templates/
  10. ```
  11. If this setting is not set, or the files named below are not found within the directory,
  12. default templates from within the Synapse package will be used.
  13. Templates that are given variables when being rendered are rendered using [Jinja 2](https://jinja.palletsprojects.com/en/2.11.x/).
  14. Templates rendered by Jinja 2 can also access two functions on top of the functions
  15. already available as part of Jinja 2:
  16. ```python
  17. format_ts(value: int, format: str) -> str
  18. ```
  19. Formats a timestamp in milliseconds.
  20. Example: `reason.last_sent_ts|format_ts("%c")`
  21. ```python
  22. mxc_to_http(value: str, width: int, height: int, resize_method: str = "crop") -> str
  23. ```
  24. Turns a `mxc://` URL for media content into an HTTP(S) one using the homeserver's
  25. `public_baseurl` configuration setting as the URL's base.
  26. Example: `message.sender_avatar_url|mxc_to_http(32,32)`
  27. ```python
  28. localpart_from_email(address: str) -> str
  29. ```
  30. Returns the local part of an email address (e.g. `alice` in `alice@example.com`).
  31. Example: `user.email_address|localpart_from_email`
  32. ## Email templates
  33. Below are the templates Synapse will look for when generating the content of an email:
  34. * `notif_mail.html` and `notif_mail.txt`: The contents of email notifications of missed
  35. events.
  36. When rendering, this template is given the following variables:
  37. * `user_display_name`: the display name for the user receiving the notification
  38. * `unsubscribe_link`: the link users can click to unsubscribe from email notifications
  39. * `summary_text`: a summary of the notification(s). The text used can be customised
  40. by configuring the various settings in the `email.subjects` section of the
  41. configuration file.
  42. * `rooms`: a list of rooms containing events to include in the email. Each element is
  43. an object with the following attributes:
  44. * `title`: a human-readable name for the room
  45. * `hash`: a hash of the ID of the room
  46. * `invite`: a boolean, which is `True` if the room is an invite the user hasn't
  47. accepted yet, `False` otherwise
  48. * `notifs`: a list of events, or an empty list if `invite` is `True`. Each element
  49. is an object with the following attributes:
  50. * `link`: a `matrix.to` link to the event
  51. * `ts`: the time in milliseconds at which the event was received
  52. * `messages`: a list of messages containing one message before the event, the
  53. message in the event, and one message after the event. Each element is an
  54. object with the following attributes:
  55. * `event_type`: the type of the event
  56. * `is_historical`: a boolean, which is `False` if the message is the one
  57. that triggered the notification, `True` otherwise
  58. * `id`: the ID of the event
  59. * `ts`: the time in milliseconds at which the event was sent
  60. * `sender_name`: the display name for the event's sender
  61. * `sender_avatar_url`: the avatar URL (as a `mxc://` URL) for the event's
  62. sender
  63. * `sender_hash`: a hash of the user ID of the sender
  64. * `msgtype`: the type of the message
  65. * `body_text_html`: html representation of the message
  66. * `body_text_plain`: plaintext representation of the message
  67. * `image_url`: mxc url of an image, when "msgtype" is "m.image"
  68. * `link`: a `matrix.to` link to the room
  69. * `avator_url`: url to the room's avator
  70. * `reason`: information on the event that triggered the email to be sent. It's an
  71. object with the following attributes:
  72. * `room_id`: the ID of the room the event was sent in
  73. * `room_name`: a human-readable name for the room the event was sent in
  74. * `now`: the current time in milliseconds
  75. * `received_at`: the time in milliseconds at which the event was received
  76. * `delay_before_mail_ms`: the amount of time in milliseconds Synapse always waits
  77. before ever emailing about a notification (to give the user a chance to respond
  78. to other push or notice the window)
  79. * `last_sent_ts`: the time in milliseconds at which a notification was last sent
  80. for an event in this room
  81. * `throttle_ms`: the minimum amount of time in milliseconds between two
  82. notifications can be sent for this room
  83. * `password_reset.html` and `password_reset.txt`: The contents of password reset emails
  84. sent by the homeserver.
  85. When rendering, these templates are given a `link` variable which contains the link the
  86. user must click in order to reset their password.
  87. * `registration.html` and `registration.txt`: The contents of address verification emails
  88. sent during registration.
  89. When rendering, these templates are given a `link` variable which contains the link the
  90. user must click in order to validate their email address.
  91. * `add_threepid.html` and `add_threepid.txt`: The contents of address verification emails
  92. sent when an address is added to a Matrix account.
  93. When rendering, these templates are given a `link` variable which contains the link the
  94. user must click in order to validate their email address.
  95. ## HTML page templates for registration and password reset
  96. Below are the templates Synapse will look for when generating pages related to
  97. registration and password reset:
  98. * `password_reset_confirmation.html`: An HTML page that a user will see when they follow
  99. the link in the password reset email. The user will be asked to confirm the action
  100. before their password is reset.
  101. When rendering, this template is given the following variables:
  102. * `sid`: the session ID for the password reset
  103. * `token`: the token for the password reset
  104. * `client_secret`: the client secret for the password reset
  105. * `password_reset_success.html` and `password_reset_failure.html`: HTML pages for success
  106. and failure that a user will see when they confirm the password reset flow using the
  107. page above.
  108. When rendering, `password_reset_success.html` is given no variable, and
  109. `password_reset_failure.html` is given a `failure_reason`, which contains the reason
  110. for the password reset failure.
  111. * `registration_success.html` and `registration_failure.html`: HTML pages for success and
  112. failure that a user will see when they follow the link in an address verification email
  113. sent during registration.
  114. When rendering, `registration_success.html` is given no variable, and
  115. `registration_failure.html` is given a `failure_reason`, which contains the reason
  116. for the registration failure.
  117. * `add_threepid_success.html` and `add_threepid_failure.html`: HTML pages for success and
  118. failure that a user will see when they follow the link in an address verification email
  119. sent when an address is added to a Matrix account.
  120. When rendering, `add_threepid_success.html` is given no variable, and
  121. `add_threepid_failure.html` is given a `failure_reason`, which contains the reason
  122. for the registration failure.
  123. ## HTML page templates for Single Sign-On (SSO)
  124. Below are the templates Synapse will look for when generating pages related to SSO:
  125. * `sso_login_idp_picker.html`: HTML page to prompt the user to choose an
  126. Identity Provider during login.
  127. This is only used if multiple SSO Identity Providers are configured.
  128. When rendering, this template is given the following variables:
  129. * `redirect_url`: the URL that the user will be redirected to after
  130. login.
  131. * `server_name`: the homeserver's name.
  132. * `providers`: a list of available Identity Providers. Each element is
  133. an object with the following attributes:
  134. * `idp_id`: unique identifier for the IdP
  135. * `idp_name`: user-facing name for the IdP
  136. * `idp_icon`: if specified in the IdP config, an MXC URI for an icon
  137. for the IdP
  138. * `idp_brand`: if specified in the IdP config, a textual identifier
  139. for the brand of the IdP
  140. The rendered HTML page should contain a form which submits its results
  141. back as a GET request, with the following query parameters:
  142. * `redirectUrl`: the client redirect URI (ie, the `redirect_url` passed
  143. to the template)
  144. * `idp`: the 'idp_id' of the chosen IDP.
  145. * `sso_auth_account_details.html`: HTML page to prompt new users to enter a
  146. userid and confirm other details. This is only shown if the
  147. SSO implementation (with any `user_mapping_provider`) does not return
  148. a localpart.
  149. When rendering, this template is given the following variables:
  150. * `server_name`: the homeserver's name.
  151. * `idp`: details of the SSO Identity Provider that the user logged in
  152. with: an object with the following attributes:
  153. * `idp_id`: unique identifier for the IdP
  154. * `idp_name`: user-facing name for the IdP
  155. * `idp_icon`: if specified in the IdP config, an MXC URI for an icon
  156. for the IdP
  157. * `idp_brand`: if specified in the IdP config, a textual identifier
  158. for the brand of the IdP
  159. * `user_attributes`: an object containing details about the user that
  160. we received from the IdP. May have the following attributes:
  161. * `display_name`: the user's display name
  162. * `emails`: a list of email addresses
  163. * `localpart`: the local part of the Matrix user ID to register,
  164. if `localpart_template` is set in the mapping provider configuration (empty
  165. string if not)
  166. The template should render a form which submits the following fields:
  167. * `username`: the localpart of the user's chosen user id
  168. * `sso_new_user_consent.html`: HTML page allowing the user to consent to the
  169. server's terms and conditions. This is only shown for new users, and only if
  170. `user_consent.require_at_registration` is set.
  171. When rendering, this template is given the following variables:
  172. * `server_name`: the homeserver's name.
  173. * `user_id`: the user's matrix proposed ID.
  174. * `user_profile.display_name`: the user's proposed display name, if any.
  175. * consent_version: the version of the terms that the user will be
  176. shown
  177. * `terms_url`: a link to the page showing the terms.
  178. The template should render a form which submits the following fields:
  179. * `accepted_version`: the version of the terms accepted by the user
  180. (ie, 'consent_version' from the input variables).
  181. * `sso_redirect_confirm.html`: HTML page for a confirmation step before redirecting back
  182. to the client with the login token.
  183. When rendering, this template is given the following variables:
  184. * `redirect_url`: the URL the user is about to be redirected to.
  185. * `display_url`: the same as `redirect_url`, but with the query
  186. parameters stripped. The intention is to have a
  187. human-readable URL to show to users, not to use it as
  188. the final address to redirect to.
  189. * `server_name`: the homeserver's name.
  190. * `new_user`: a boolean indicating whether this is the user's first time
  191. logging in.
  192. * `user_id`: the user's matrix ID.
  193. * `user_profile.avatar_url`: an MXC URI for the user's avatar, if any.
  194. `None` if the user has not set an avatar.
  195. * `user_profile.display_name`: the user's display name. `None` if the user
  196. has not set a display name.
  197. * `sso_auth_confirm.html`: HTML page which notifies the user that they are authenticating
  198. to confirm an operation on their account during the user interactive authentication
  199. process.
  200. When rendering, this template is given the following variables:
  201. * `redirect_url`: the URL the user is about to be redirected to.
  202. * `description`: the operation which the user is being asked to confirm
  203. * `idp`: details of the Identity Provider that we will use to confirm
  204. the user's identity: an object with the following attributes:
  205. * `idp_id`: unique identifier for the IdP
  206. * `idp_name`: user-facing name for the IdP
  207. * `idp_icon`: if specified in the IdP config, an MXC URI for an icon
  208. for the IdP
  209. * `idp_brand`: if specified in the IdP config, a textual identifier
  210. for the brand of the IdP
  211. * `sso_auth_success.html`: HTML page shown after a successful user interactive
  212. authentication session.
  213. Note that this page must include the JavaScript which notifies of a successful
  214. authentication (see https://matrix.org/docs/spec/client_server/r0.6.0#fallback).
  215. This template has no additional variables.
  216. * `sso_auth_bad_user.html`: HTML page shown after a user-interactive authentication
  217. session which does not map correctly onto the expected user.
  218. When rendering, this template is given the following variables:
  219. * `server_name`: the homeserver's name.
  220. * `user_id_to_verify`: the MXID of the user that we are trying to
  221. validate.
  222. * `sso_account_deactivated.html`: HTML page shown during single sign-on if a deactivated
  223. user (according to Synapse's database) attempts to login.
  224. This template has no additional variables.
  225. * `sso_error.html`: HTML page to display to users if something goes wrong during the
  226. OpenID Connect authentication process.
  227. When rendering, this template is given two variables:
  228. * `error`: the technical name of the error
  229. * `error_description`: a human-readable message for the error