Updating placeholder content

  • Last updated on February 17, 2023 at 12:56 AM

You can use placeholder content in the hosted knowledge base in a similar way that you can in the Assistant.

To use placeholders, first add content in two curly braces to your content such as this {{my_placeholder}}

Then to make the updates in your KB. Goto the KB customise screen and make sure you have enabled "Advanced options".

Then you can put code similar to this in the Custom JS section.

window.kb.on('article:load', function(data) {
    const replacements = {
        my_placeholder: 'new content',
        phone_number: '1800 CALLUS',
        domain: 'oursite.com',
    };
    let title = data.title;
    let body = data.body;

    Object.keys(replacements).forEach(function(placeholder) {
        title = title.replaceAll('{{' + placeholder + '}}', replacements[placeholder]);
        body = body.replaceAll('{{' + placeholder + '}}', replacements[placeholder]);
    });

    window.kb.updateArticle(data.id, title, body);
});

Was this article helpful?