# Interpolation Keys for Customizing Text and System Email Templates

**URL:** https://meta.discourse.org/t/interpolation-keys-for-customizing-text-and-system-email-templates/264604
**Category:** Site Management
**Tags:** explanation
**Created:** [May 11, 2023, 12:33am UTC](https://meta.discourse.org/t/interpolation-keys-for-customizing-text-and-system-email-templates/264604 "2023-05-11T00:33:57Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Discourse](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/discourse/32/148734_2.png) [@Discourse](https://meta.discourse.org/u/Discourse)
#### Post date: [May 11, 2023, 12:33am UTC](https://meta.discourse.org/t/interpolation-keys-for-customizing-text-and-system-email-templates/264604/1 "2023-05-11T00:33:57Z")

</div>

> 🔖 This guide provides a detailed overview of interpolation keys used for customizing text and system email templates in Discourse.
> 
> 🙋 Required user level: Administrator

While [Customizing text in Discourse](https://meta.discourse.org/t/customize-any-text-in-discourse/36092) or [Customizing specific email templates](https://meta.discourse.org/t/customize-specific-email-templates/88323) 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:

 ![image](https://global.discourse-cdn.com/meta/original/4X/1/6/f/16fc47c3de91e0f8c2c26fc7d0fa905b5c60ce19.png)

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 tied to the corresponding template.

However, certain template groups allow additional interpolation keys to be added beyond those already present in the default template.

## Additional Interpolation Keys

### Welcome User System Message

For `system_messages.welcome_user` templates, you can add these additional keys:

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

These values are provided by the `SystemMessage` class at runtime (See [system\_message.rb](https://github.com/discourse/discourse/blob/main/lib/system_message.rb) for the related Discourse code).

### User Notification Emails

For `user_notifications` and related email templates (including `unsubscribe_mailing_list` and `unsubscribe_link`), many additional keys are available, including `topic_title`, `username`, `site_name`, `url`, `unsubscribe_url`, and others.

For the complete and up-to-date list of all allowed custom interpolation keys and which template groups they apply to, refer to the `ALLOWED_CUSTOM_INTERPOLATION_KEYS` in the [Discourse source code for translation\_override.rb](https://github.com/discourse/discourse/blob/main/app/models/translation_override.rb).

> Last edited by @SaraDev 2024-07-26T20:16:22Z
> 
> > **Check document**
> >
> > Perform check on document:

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [May 11, 2023, 9:23am UTC](https://meta.discourse.org/t/interpolation-keys-for-customizing-text-and-system-email-templates/264604/2 "2023-05-11T09:23:55Z")

</div>

> [@SaraDev](#):
>
> You can use all `system_messages.*` 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 which adds `username, name, name_or_username` as additional interpolation keys. See [system\_message.rb](https://github.com/discourse/discourse/blob/6fa9a8990d07f942ee52b3d721135b84d79d8a7c/lib/system_message.rb#L27-L36) for the related Discourse code.

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.

---

<div class="post-metadata">

### Author: ![SaraDev](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/saradev/32/335139_2.png) [@SaraDev](https://meta.discourse.org/u/SaraDev)
#### Post date: [May 11, 2023, 4:49pm UTC](https://meta.discourse.org/t/interpolation-keys-for-customizing-text-and-system-email-templates/264604/3 "2023-05-11T16:49:31Z")

</div>

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

---

<div class="post-metadata">

### Author: ![gassim](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gassim/32/220910_2.png) [@gassim](https://meta.discourse.org/u/gassim)
#### Post date: [October 22, 2024, 4:40am UTC](https://meta.discourse.org/t/interpolation-keys-for-customizing-text-and-system-email-templates/264604/4 "2024-10-22T04:40:20Z")

</div>

Hi!

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

Thanks!

---

<div class="post-metadata">

### Author: ![gassim](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gassim/32/220910_2.png) [@gassim](https://meta.discourse.org/u/gassim)
#### Post date: [November 19, 2024, 2:31pm UTC](https://meta.discourse.org/t/interpolation-keys-for-customizing-text-and-system-email-templates/264604/5 "2024-11-19T14:31:21Z")

</div>

> [@Discourse](#):
>
> `username`: The username of the user

Hi!  
It says that this key is not valid:

 ![image](https://global.discourse-cdn.com/meta/original/4X/f/9/3/f939a3f82b44875922c751e1bd7c50e0bd92ee52.png)

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

---

<div class="post-metadata">

### Author: ![Jagster](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagster/32/192154_2.png) [@Jagster](https://meta.discourse.org/u/Jagster)
#### Post date: [November 19, 2024, 2:47pm UTC](https://meta.discourse.org/t/interpolation-keys-for-customizing-text-and-system-email-templates/264604/6 "2024-11-19T14:47:06Z")

</div>

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

---

<div class="post-metadata">

### Author: ![gassim](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gassim/32/220910_2.png) [@gassim](https://meta.discourse.org/u/gassim)
#### Post date: [November 19, 2024, 3:50pm UTC](https://meta.discourse.org/t/interpolation-keys-for-customizing-text-and-system-email-templates/264604/7 "2024-11-19T15:50:29Z")

</div>

> [@Discourse](#):
>
> You can also use all `system_messages.welcome_user` keys in text and email template customizations

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

---

<div class="post-metadata">

### Author: ![Jagster](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagster/32/192154_2.png) [@Jagster](https://meta.discourse.org/u/Jagster)
#### Post date: [November 19, 2024, 4:14pm UTC](https://meta.discourse.org/t/interpolation-keys-for-customizing-text-and-system-email-templates/264604/8 "2024-11-19T16:14:39Z")

</div>

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 🤷‍♂️

---

<div class="post-metadata">

### Author: ![gassim](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gassim/32/220910_2.png) [@gassim](https://meta.discourse.org/u/gassim)
#### Post date: [November 19, 2024, 7:20pm UTC](https://meta.discourse.org/t/interpolation-keys-for-customizing-text-and-system-email-templates/264604/9 "2024-11-19T19:20:48Z")

</div>

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

 ![image](https://global.discourse-cdn.com/meta/original/4X/3/1/c/31c8479f950764d77e6000f75bc68ffd08897ec7.png)

---

<div class="post-metadata">

### Author: ![Jagster](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagster/32/192154_2.png) [@Jagster](https://meta.discourse.org/u/Jagster)
#### Post date: [November 19, 2024, 8:39pm UTC](https://meta.discourse.org/t/interpolation-keys-for-customizing-text-and-system-email-templates/264604/10 "2024-11-19T20:39:16Z")

</div>

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.
