# Category specific Disclaimer

**URL:** https://meta.discourse.org/t/category-specific-disclaimer/263168
**Category:** Development
**Created:** [April 28, 2023, 10:24am UTC](https://meta.discourse.org/t/category-specific-disclaimer/263168 "2023-04-28T10:24:35Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![nstoecki42](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nstoecki42/32/75218_2.png) [@nstoecki42](https://meta.discourse.org/u/nstoecki42)
#### Post date: [April 28, 2023, 10:24am UTC](https://meta.discourse.org/t/category-specific-disclaimer/263168/1 "2023-04-28T10:24:35Z")

</div>

Hi,

I tried to add a Disclaimer on a specific Category. I had the Idea to have a “banner” - like  
`This is User's first post - let's welcome the new member to our community!`  
or  
`It's been a while since we've seen USER - the last post was 1 year ago.`  
above each Post.

I tried to archive this with:

> **common/head\_tag.html**
>
> ```js
> <script type="text/discourse-plugin" version="0.8">
> api.decorateWidget('post:after', (helper, args) => {
> if (args.topic.category_id === 51) { // My Category
> const $post = helper.find('.cooked');
> const disclaimerText = api.decorateCooked(helper, args, settings.MY_DISCLAIMER);
> $post.prepend(`<div class="disclaimer">${disclaimerText}</div>`);
> }
> });
> </script>
> 
> ```

Just to be complete here is the

> **settings.yml**
>
> ```yml
> MY_DISCLAIMER:
> type: string
> default: 'This is a Category that comes with limited warranty and is to be used at your own risk.'
> description: Disclaimer Text for Category
> 
> ```

and there is also `common/common.scss` with the `.disclaimer` class in it.

But when I active that the Post itself is no longer shown, the content area is just blank.

Thanks for any help!

---

<div class="post-metadata">

### Author: ![Stephen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stephen/32/95011_2.png) [@Stephen](https://meta.discourse.org/u/Stephen)
#### Post date: [April 28, 2023, 10:44am UTC](https://meta.discourse.org/t/category-specific-disclaimer/263168/2 "2023-04-28T10:44:27Z")

</div>

Is it blank in the source too?

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [April 28, 2023, 12:27pm UTC](https://meta.discourse.org/t/category-specific-disclaimer/263168/3 "2023-04-28T12:27:58Z")

</div>

Hi, welcome back!

If you see blank, it’s because you have an error. `find` doesn’t exist in the `helper`.  
You can usually see that in the browser console (F12).

You probably want something like that:

```js
api.decorateWidget('post:before', (helper, args) => {
    if (helper.widget.model.topic.category_id === 51) {
        return helper.h("div.disclaimer", settings.MY_DISCLAIMER)
    }
});

```

or using raw HTML:

```js
const RawHtml = require("discourse/widgets/raw-html").default;

api.decorateWidget('post:before', (helper, args) => {
    if (helper.widget.model.topic.category_id === 51) {
         return new RawHtml({html: `<div class="container">${settings.MY_DISCLAIMER}</div>`})
    }
});

```

You can read [this post](https://meta.discourse.org/t/how-to-add-customer-html-after-post-1/123068/2) explaining how this `h` helper works.

You can do the following if you want to add some HTML before the cooked content:

```js
api.decorateWidget('post-contents:before', (helper, args) => {
    const { topic } = helper.widget.findAncestorModel();

    if (topic && topic.category_id === 51) {
         return helper.h("div.disclaimer", settings.MY_DISCLAIMER);
    }
});

```

---

<div class="post-metadata">

### Author: ![nstoecki42](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nstoecki42/32/75218_2.png) [@nstoecki42](https://meta.discourse.org/u/nstoecki42)
#### Post date: [May 2, 2023, 8:49am UTC](https://meta.discourse.org/t/category-specific-disclaimer/263168/4 "2023-05-02T08:49:00Z")

</div>

Thanks @Arkshine, that helpt a lot!

I used the following Code due to I want to display the Text above all like the other, mentioned banners.

```plaintext
api.decorateWidget('post:before', (helper, args) => {
    if (helper.widget.model.topic.category_id === 51) {
        return helper.h("div.disclaimer", settings.MY_DISCLAIMER)
    }
});

```

Greetings!

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [June 1, 2023, 8:49am UTC](https://meta.discourse.org/t/category-specific-disclaimer/263168/5 "2023-06-01T08:49:22Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
