How to use the nunjucks/browser/nunjucks.renderString function in nunjucks

To help you get started, we’ve selected a few nunjucks examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github frappe / frappejs / client / desk / printpage.js View on Github external
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;
        }
    }
}
github frappe / frappejs / common / print.js View on Github external
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>
    `;
}