Is it possible to change Topic Title prompt for a category?

Discourse assigns an id to each category that gets created, so you can use that to accomplish your goal.

You’ll need to add a bit of custom code to a theme component and add it to your active theme(s)

Here’s the commented code for what you want to achieve.

<script type="text/discourse-plugin" version="0.8">
  // options you can change
  const targetCategoryId = 6; // change this to the category you want to target
  const placeHolderForCategory = "CHANGE_THIS_TEXT_BUT_KEEP_THE_QUOTES";

  // no need to change anything below this line. Stop here if you're an admin.
  const discourseComputed = require("discourse-common/utils/decorators")
    .default;

  // not a remote component
  const currentLocale = I18n.currentLocale();
  I18n.translations[
    currentLocale
  ].js.composer.custom_category_placeholder = placeHolderForCategory;

  // changes placeholder for target category, otherwise, fallback to
  // defaults.
  api.modifyClass("model:composer", {
    @discourseComputed("canEditTopicFeaturedLink")
    titlePlaceholder() {
      return this.category && this.category.id === targetCategoryId
        ? "composer.custom_category_placeholder"
        : this._super();
    },
  });
</script>

This goes into the common > header tab of your component.

You can get the category id by visiting the page for that specific category and checking the URL

For example,

The id for the #support category here on Meta is 6 (the last digit in the URL here)

support - Discourse Meta

In the snippet above, the id (number) for your target category should replace “6” in targetCategoryId

The other option is pretty straightforward, change the text to what you’d like to show as the placeholder for the title for that category.

4 Likes