Using placeholder content

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

NB To see instructions for updating placeholders in your Knowledge base see here

In some cases, it be helpful to use placeholders in your content so you can swap in content at display time.

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

Then when installing the Assistant on your site, you can use the JavaScript APIs updateArticle method to replace the title and body with a version that swaps your placeholder content with what you need.

Some example code below can be seen to show how you might go about this:

window._elev.on('article:data:loaded', 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]);
    });


    _elev.updateArticle(data.articleId, title, body);
});


Was this article helpful?