# カテゴリとトピックテンプレート付きの新しいトピック作成ボタン

**URL:** https://meta.discourse.org/t/create-a-new-topic-button-with-category-and-topic-template/85775
**Category:** Administrators
**Tags:** how-to
**Created:** [2018 年 4 月 20 日午前 4:07 UTC](https://meta.discourse.org/t/create-a-new-topic-button-with-category-and-topic-template/85775 "2018-04-20T04:07:12Z")
**Posts on this page:** 1
**Showing post:** 13

<div class="post-metadata">

### Author: ![Johani](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/johani/32/176920_2.png) [@Johani](https://meta.discourse.org/u/Johani)
#### Post date: [2018 年 8 月 30 日午前 9:02 UTC](https://meta.discourse.org/t/create-a-new-topic-button-with-category-and-topic-template/85775/13 "2018-08-30T09:02:26Z")

</div>

Yes, that would also be possible as well. You can use something like this in the `header` section of a theme component

```plaintext
<script type="text/discourse-plugin" version="0.8">
const i18nTopicLable = I18n.lookup("topic.create");
api.modifyClass("component:create-topic-button", {
  didInsertElement: function() {
    var button = $(this),
      category = button[0].parentView.get("category"),
      label = button[0].label,
      newTopicLabel = "topic.create",
      buttonText = "";

    if (category) {
      categoryName = category.name;

      if (label != newTopicLabel) {
        return;
      } else {
        switch (categoryName) {
          case "category1": // category name
            buttonText = "category1 text"; // button text
            break;
          // repeat
          case "category2":
            buttonText = "category2 text";
            break;
          // add more above this line
          default:
            buttonText = i18nTopicLable;
        }
        $("#create-topic .d-button-label").text(buttonText);
      }
    }
  }
});
</script>

```

To add new categories, you only need to add this above where it says default

```plaintext
case "category":
  buttonText = "text";
  break;

```

If you have a pending draft and the button says “open draft” the script won’t fire.

I’ve created a small [preview on theme creator](https://theme-creator.discourse.org/theme/Johani/category-based-topic-button) and changed the text for the movies, tech, school, videos and gaming categories

**Edit:**  
@dax informed me that I had missed something in the snippet I posted previously and so I updated it and the preview so be sure to use the latest one @tophee

---

_[View the full topic](https://meta.discourse.org/t/create-a-new-topic-button-with-category-and-topic-template/85775)._
