Add template renderer for extensions

This commit is contained in:
Cohee
2023-08-25 20:34:26 +03:00
parent 91d13efcef
commit b32a085e41
2 changed files with 17 additions and 4 deletions

View File

@ -496,9 +496,10 @@ function getUrlSync(url, cache = true) {
}).responseText;
}
function renderTemplate(templateId, templateData = {}, sanitize = true, localize = true) {
export function renderTemplate(templateId, templateData = {}, sanitize = true, localize = true, fullPath = false) {
try {
const templateContent = getUrlSync(`/scripts/templates/${templateId}.html`);
const pathToTemplate = fullPath ? templateId : `/scripts/templates/${templateId}.html`;
const templateContent = getUrlSync(pathToTemplate);
const template = Handlebars.compile(templateContent);
let result = template(templateData);