I have a piece of code that loads in a html template with handlebar expressions in it.
The html is loaded into docHTML based on values in a Javascript object (layout of this object is not really important for this example).
Then it will go through the text in docHTML and does a find/replace for any placeholder that I defined and replaces it with a handlebar snippet.
As I can define multiple placeholders it checks for this in a for loop.
After this is done I have the resulting text and then render the final HTML with the Handlebars.render.
And finally I make sure that everything is displayed on the document.
I notice that when I render the main HTML with handlebar expressions it works fine but the html in the handlebar snippet gets rendered as text.
I have already used a triple { and } to make sure this is rendered as HTML but this does not seem to work.
Do note that the information is read in fine, it is just represented as text (only the snippet and not the main html) which it should not do.
How can I make sure that everything is properly rendered as HTML instead?
// First load the handlebar content
docHTML = loadtext("file:///" + gDocument.replacements[i].value);
// Also check if there are any handlebar snippets in the content that need to be replaced
for (var j = 0; j < gDocument.handlebars.length; j++) {
docHTML = replaceAll(docHTML, gDocument.handlebars[j].placeholder, "{{{+ file:///" + replaceAll(gDocument.handlebars[j].value, "\\", "/") + " }}}");
}
// Render the handlebar information (if any)
docResult = Handlebars.render( docHTML, { gTexts, gDocument, record });
// Only do something if we can load the file
if (docResult != "") {
// And now replace the placeholders with the loaded information
result.replaceWith(docResult);
}
function replaceAll(str, find, replace) {
// Escape special characters for use in a regular expression
const escapedFind = find.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
return str.replace(new RegExp(escapedFind, 'g'), replace);
}