Discourse Templates

:discourse2: Summary Discourse Templates allows the creation of content templates for repeated use. The templates are stored as topics in a special category, where they can be edited and discussed as needed.
:hammer_and_wrench: Repository Link https://github.com/discourse/discourse-templates
:open_book: Install Guide How to install plugins in Discourse

:information_source: This plugin is pretty much a new version of Discourse Canned Replies but it is more flexible and stores the templates in a different way.

Features

This plugin uses one or more categories to store the templates for later use. The first post on each topic in these categories will be used as the template for the replies.

This approach provides a lot more functionality then it was available before with discourse-canned-replies as each template will have edit history, can have associated tags, and the subsequent posts can be used to discuss the content of the template if needed.

Only visible topics will be used as templates, so topics unlisted and archived won’t be listed.

The plugin also leverages the categories security settings to check which users can use the templates. If the user can read the topics in the category then the option to “insert templates” in the composer will be available to use. The user will only be able to see the templates/topics in the categories that they have access

Multiple parent categories and/or sub-categories can be used to provide different sets of templates to be used to different groups of users and organize the templates.

Private templates

The plugin also supports private templates. Private templates are private messages tagged as templates. These messages will be available as templates only to the author of the message.

Archived messages won’t be listed as templates.

:bulb: You can find all your private templates at:
/u/{USER-NAME}/messages/tags/{PRIVATE-TEMPLATE-TAG}

Settings:

  • discourse templates enabled: Activates the plugin
  • discourse templates categories: Categories that used to store the templates. Each topic in theses categories and their sub-categories will be used as template and will be available to users that can see them in their original categories.
  • discourse templates enable private templates: Enables the use of private templates.
  • discourse templates groups allowed private templates: Groups of users allowed to use private templates.

:warning: Staff members are always allowed.

  • discourse templates private templates tags: Tags that will be used to mark private messages as templates.

How to use it

After installing the plugin, you will need to create at least a category to store the templates.

Notice that every user that has access to read the topics in this category will be able to use the plugin functionality in the composer.

:bulb: Pro-tip: The same settings to edit topics will be applied to “template” topics. If you want that anyone with write access in the category be able to edit the existing templates, you should activate Make new topics wikis by default on the category settings.

After that, specify the category in the plugin settings.

That’s it. Now you only have to create some topics in the specified category and they will be available to use as templates.

If you want you can create sub-categories to better organize the templates or to provide different sets of replies to multiple groups of users.

To insert templates you must first open the reply composer and click the extras button, then select the option “Insert template”

Select the desired template, you can search by text or tags and click on the “paste” icon.

Keyboard shortcut
You can use Ctrl+Shift+I on PCs or +Shift+I on Macs to insert templates.

:bulb: The keyboard shortcut will work inside any textarea on Discourse

Private templates

:warning: Private templates will only work in instances with both private messages and tags enabled.

You need to configure the following settings Discourse settings in order for it to work:

  • tagging enabled: must be enabled.
  • enable personal messages: should be enabled if you want to make the feature available for non-staff users.
  • pm tags allowed for groups: you will need to allow the groups that will use private templates to tag private messages.

To use private templates you must first enable it in settings, assign the groups of users that can use it and assign at least a tag to mark the PMs as a template.

To create a personal template the users must:

  • send an unencrypted personal message to themselves tagged with one of the tags configured in the plugin settings. Only to the author of the message will view it as a private template.

:bulb: Private messages sent to other users also can be also be tagged but only the author of the message will be able to use it as a template.

Pre-filled variables

The plugin supports the following variables on the templates:

  • my_username
  • my_name
  • topic_title
  • topic_url
  • original_poster_username
  • original_poster_name
  • reply_to_username
  • reply_to_name
  • last_poster_username
  • reply_to_or_last_poster_username.

All the above variables supports fallback text and will strip out the variable if fallback is not specified and the variable can’t be replaced.

Both title and body supports variable replacement.

Example:

Hi %{reply_to_username,fallback:there},

...

Regards,
%{my_name}

If the reply_to_username is not available, the template will be:

Hi there,

...

Regards,
Arpit Jalan

Migration from discourse-canned-replies

There is a rake task to migrate the existing canned replies to templates:

rake "discourse-templates:migrate-from-canned-replies"

This took only a few seconds to to run on Meta to migrate 47 canned replies so it should be safe to use unless you have a staggering amount of canned replies.

TODO

  • extend functionality to other places beyond the composer :white_check_mark:
  • allow using more than one parent category as template sources :white_check_mark:

Changelog

  • 2022-07-14T03:00:00Z: Added ability to use multiple parent categories as source for templates
  • 2022-07-18T03:00:00Z: Private templates
  • 2022-08-10T03:00:00Z: Global keyboard shortcut
31 Likes