How to replace text and update dynamically

We need to add a disclaimer or disclosure to certain posts (about 100 of them and counting). The disclosure might change in the future, so I would like to add [DISCLOSURE-GOES-HERE] to each of the 100 posts. We can add it manually, that’s no problem. But when we update our disclosure in the future, I only want to change it one place.

What I’ve tried:

  1. Watched Words. The problem is that existing posts do not show the updated disclosure until you edit the post. That defeats the purpose for this use case.

  2. Javascript to replace innerHTML of the element. I must have done it wrong- this caused errors about replacing a child node:

<script type="text/discourse-plugin" version="0.8">
    var disclosures = "• Important Disclosures:  We are not responsible, etc, etc."
    api.decorateCooked($elem => {
        var el = $elem[0];
        el.innerHTML = el.innerHTML.replace('[DISCLOSURE-GOES-HERE]', disclosures);
    });
</script>
  1. Auto-linkify theme component. Love it for other things, but I want to display the disclosure text, not a link to the disclosure.

  2. I know you can replace text from the rails console, but I want moderators to maintain it.

I have done similar things based on the code from the Auto Linkify Words component.

1 Like

If you don’t change the disclaimer often then maybe you can Rebake all posts matching a pattern when you change it.

That solution has the advantage not not re-rendering that text on every post every time it’s viewed.

5 Likes

There is a textual approach that will assist here as well: make the disclosure message “evergreen”, and link to the details of the warning. Rather than…

Important Disclosures: We are not responsible, liable, or even knowledgeable about the claims in this topic.

…go for something like:

Important Disclosures: this topic contains content that may need more context, provided at Disclosure List

Then the bulk of your updating can be that one page, which could also be a topic in Discourse (easy to edit/update!). :slight_smile:

1 Like