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:
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:
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 explaining how this h
helper works.
You can do the following if you want to add some HTML before the cooked content:
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);
}
});