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

I created a category on my forum called “Contest Submissions”. This category will be reserved to submissions for when our company runs a contest. I’ve figured out how to create a topic template for the body of a new topic, but I can’t figure out how to edit the title of that topic. Here’s what I mean:

Notice how my title prompt just says “an interesting title” right now. I want to change it to say “The title of your project”. But I only want to change it for that specific category. Not the whole forum. How do I do that?

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.

3 Likes