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!

Hi!
It says that this key is not valid:

P.S.
I’m replacing in text not email (does it make a difference)? Thanks!

I don’t think those are global and free to use everywhere.

1 Like

Thanks @Jagster ! I’m using them in the text customization so based on the topic post, it’s supposed to work?

Topic is actually about email templates and those texts. So, you can’t use interpolations keys outside right context. That’ts why we have other keys for emails, other for some AI prompts etc.

Sure, plugins can do a lot of things, but this time not out of the box.

And disclaimer: I’m just another end user and I can be horrible wrong too. But I’m quite sure I’m right — and that’s why your try doesn’t work :man_shrugging:

Okay, thank you so much for your support. It looks like it’s not working even in used in an email template:

My bet is you can use %{username} in ”User did…” templates, and all other templates don’t support it.

But we’ll see tomorrow when all gurus are waken.