Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async renderTemplate() {
this.printFormat = await frappe.getDoc('PrintFormat', this.meta.print.printFormat);
let doc = await frappe.getDoc(this.doctype, this.name);
let context = {doc: doc, frappe: frappe};
frappe.desk.setActiveDoc(doc);
try {
this.body.innerHTML = `<div class="print-page">${nunjucks.renderString(this.printFormat.template, context)}</div>`;
// this.setTitle(doc.name);
} catch (e) {
this.renderError('Template Error', e);
throw e;
}
}
}
async function getHTML(doctype, name) {
const meta = frappe.getMeta(doctype);
const printFormat = await frappe.getDoc('PrintFormat', meta.print.printFormat);
let doc = await frappe.getDoc(doctype, name);
let context = {doc: doc, frappe: frappe};
let html;
try {
html = nunjucks.renderString(printFormat.template, context);
} catch (error) {
console.log(error);
html = '';
}
return `
<div class="print-page">
${html}
</div>
`;
}