Interpolation Keys for Customizing Text and System Email Templates

:bookmark: This guide provides a detailed overview of interpolation keys used for customizing text and system email templates in Discourse.

:person_raising_hand: Required user level: Administrator

While Customizing text in Discourse or Customizing specific email templates you may have noticed that there are placeholder variables available in some templates.

In Discourse we call these Interpolation Keys.

Understanding interpolation keys

Interpolation keys are placeholders available in certain Discourse templates. They allow you to insert dynamic content into your text and email templates.

Example of Interpolation Keys for the Account Created email template:

These keys, such as %{username} or %{site_name} , will be replaced with actual data when the email is sent.

In general, these placeholders can be moved around within the template they belong to, but they are only available in that template and cannot be moved around to different templates, as they are all backed by server code that’s to the corresponding template.

However, there are some additional Interpolation Keys allowed in text and email templates.

General Interpolation Keys

Here’s a list of some general interpolation keys you can use across all email templates:

  • username: The username of the user
  • name: The full name of the user
  • name_or_username: Either the user’s full name or username

You can also use all system_messages.welcome_user keys in text and email template customizations as long as they have subject_template and text_body_template subkeys, because all of them should be handled by the SystemMessage class (See system_message.rb for the related Discourse code).

For a complete list of allowed custom interpolation keys, refer to the ALLOWED_CUSTOM_INTERPOLATION_KEYS in the Discourse source code for translation_override.rb.

Last edited by @SaraDev 2024-07-26T20:16:22Z

Check documentPerform check on document:
9 Likes

That’s not correct. Currently that works only for system_messages.welcome_user, but we could extend it to all other keys. This is pr-welcome material.

4 Likes

Thanks for pointing that out, this has been updated in the guide.

2 Likes

Hi!

How can I modify the value for some of these interpolation keys? For instance, %{search_answer}

Thanks!