How to use the compile function from handlebars
Find comprehensive JavaScript handlebars.compile code examples handpicked from public code repositorys.
GitHub: nasa/cumulus
474 475 476 477 478 479 480 481 482 483
rule.collection.name += postfix; rule.provider += postfix; } rule = Object.assign(rule, overrides); const ruleTemplate = Handlebars.compile(JSON.stringify(rule)); const templatedRule = JSON.parse(ruleTemplate({ AWS_ACCOUNT_ID: process.env.AWS_ACCOUNT_ID, AWS_REGION: process.env.AWS_REGION, ...config,
102
224
24
+ 5 other calls in file
GitHub: flatsheet/flatsheet
9 10 11 12 13 14 15 16 17
"<section id=\"modal\" class=\"modal-wrapper\">\n <button id=\"close-modal\"><i class=\"fa fa-times\"></i> close</button>\n <div class=\"modal-content\">\n {{{ content }}}\n </div>\n</section>\n" ), newSheet: Handlebars.compile( "<h1>Create new blank sheet</h1>\n<form action=\"/sheets/new\" method=\"post\">\n <input type=\"text\" name=\"name\" placeholder=\"name of sheet\"><br>\n <input type=\"text\" name=\"description\" placeholder=\"description\"><br>\n <input type=\"submit\" value=\"Create sheet\">\n</form>\n" ), newSheetFromCSV: Handlebars.compile( "<h1>Create sheet from CSV file</h1>\n<form action=\"/sheets/new/csv\" method=\"post\" enctype=\"multipart/form-data\">\n <input type=\"text\" name=\"name\" placeholder=\"name of sheet\"><br>\n <input type=\"text\" name=\"description\" placeholder=\"description\"><br>\n <input type=\"file\" name=\"csv-file\"><br>\n <br>\n <input type=\"submit\" value=\"Create sheet\">\n</form>\n" ) };
18
202
14
+ 11 other calls in file
GitHub: seattleio/space
10 11 12 13 14 15 16 17 18
fastClick(document.body); var flatsheet = new Flatsheet(); /* pull in template for showing info about a location */ var spaceTemplate = Handlebars.compile("<div class=\"space clearfix\">\n <h3 class=\"space-name\">{{ name }}</h3>\n <div class=\"space-description\">\n {{{ description }}}\n </div>\n <div class=\"space-info\">\n <div class=\"pull-left\">\n <div>\n <span class=\"space-neighborhood\">\n {{ neighborhood }}\n </span>\n\n {{#if phone }} |\n <span class=\"space-phone\">\n {{ phone }}\n </span>\n {{/if}}\n\n {{#if email }} |\n <span class=\"space-email\">\n {{ email }}\n </span>\n {{/if}}\n </div>\n\n <div class=\"space-address\">\n <a href=\"https://maps.google.com?daddr={{ address }}\" target=\"_blank\">Directions | {{ address }}</a>\n </div>\n\n <div class=\"space-website\">\n <a href=\"{{ website }}\" target=\"_blank\">{{ website }}</a>\n </div>\n </div>\n\n <div class=\"pull-right\">\n <div class=\"space-social\">\n {{#if twitter }}\n <a href=\"{{ twitter }}\" target=\"_blank\"><i class=\"fa fa-twitter\"></i></a>\n {{/if}}\n\n {{#if facebook }}\n <a href=\"{{ facebook }}\" target=\"_blank\"><i class=\"fa fa-facebook\"></i></a>\n {{/if}}\n </div>\n </div>\n</div>\n"); /* set image path */ L.Icon.Default.imagePath = 'node_modules/leaflet/dist/images/';
0
3
1
+ 3 other calls in file
34 35 36 37 38 39 40 41 42 43
}; var compile = function(src, options, callback) { var tmpl; try { tmpl = handlebars.compile(src, options); } catch(ex) { callback(ex, null); } callback(null, tmpl);
21
0
1
+ 7 other calls in file
778 779 780 781 782 783 784 785 786 787
} } // handle template if (template) { const hTemplate = Handlebars.compile(template.trim()); formattedVal = hTemplate({ value }).trim(); } // handle excludes
77
54
20
+ 2 other calls in file
163 164 165 166 167 168 169 170 171 172
router.post("/sendconfirmationinvoice/:carrentalId", (request, response) => { let result = { returnCode: 0, data: null, returnMessage: "" }; readHTMLFile( __dirname + "../../InvoiceEmailTemplate/newsletter.html", function (err, html) { let template = handlebars.compile(html); generatePDFDetails(request.params.carrentalId).then((printableModel) => { let replacements = generateReplaceMents(printableModel); let htmlToSend = template(replacements); let finalId = genUniqueId(4) + "-" + printableModel.BookingId;
1
0
0
125 126 127 128 129 130 131 132 133 134
error: 'data property is not a JSON object' }); } } var template = Handlebars.compile(source); var data = template(data); res.contentType = 'text/html'; res.header('Content-Type', 'text/html'); res.send(data);
0
3
0
126 127 128 129 130 131 132 133 134 135 136
* @param {any} data JSON to pass into the Handlebars template */ async function renderTemplate(templateName, data) { const getTemplate = async (name) => { const file = await fs.readFile(`${__dirname}/templates/${name}.handlebars`, 'utf8'); return Handlebars.compile(file); }; const template = await getTemplate(templateName);
9
1
9
GitHub: GetPublii/Publii
1766 1767 1768 1769 1770 1771 1772 1773 1774 1775
desc: '' }); } try { compiledTemplate = Handlebars.compile(template); } catch(e) { this.errorLog.push({ message: 'An error (1001) occurred during parsing ' + inputFile + ' file.', desc: e.message
341
0
79
+ 2 other calls in file
GitHub: cliss/camel
658 659 660 661 662 663 664 665 666 667
return retVal; }); Handlebars.registerPartial('article', indexInfo.metadata.ArticlePartial); var dayTemplate = Handlebars.compile(indexInfo.metadata.DayTemplate); var footerTemplate = Handlebars.compile(indexInfo.metadata.FooterTemplate); var bodyHtml = ''; allPostsPaginated(function (pages) { // If we're asking for a page that doesn't exist, redirect.
55
265
27
+ 11 other calls in file
51 52 53 54 55 56 57 58 59 60
// required traitlist ?? /* if (!traitsList || traitsList.length == 0) { throw Error("traits list in config not present"); } */ const template = Handlebars.compile( (identifyTemplateConfig ? identifyTemplateConfig.trim().length === 0 ? undefined : identifyTemplateConfig
75
52
20
65 66 67 68 69 70 71 72 73 74 75
const ajv = new Ajv(); const validate = ajv.compile(schema); const getTemplate = path => { const templateString = readFileSync(path, { encoding: 'utf-8' }); const template = Handlebars.compile(templateString, { strict: true, }); return template; };
22
6
50
+ 2 other calls in file
32 33 34 35 36 37 38 39 40 41
throw new Error('Please set either a "NETWORK_NAME" or a "SUBGRAPH" environment variable'); } const subgraphTemplateFilePath = path.join(__dirname, "subgraph.template.yaml"); const source = await fs.readFile(subgraphTemplateFilePath, "utf-8"); const template = Handlebars.compile(source); const result = template(network); await fs.writeFile(path.join(__dirname, "subgraph.yaml"), result); console.log("🎉 subgraph.yaml successfully generated");
4
3
1
77 78 79 80 81 82 83 84 85 86
readHTMLFile('/detail.html', (err, html) => { if (err) { console.log("(whatsapp) error read html file: ", err); } var template = handlebars.compile(html); var replacements = { app_version: pjson.version, project_id: projectId, token: token,
3
6
1
+ 8 other calls in file
185 186 187 188 189 190 191 192 193 194 195 196
}; RendererMarkdown.prototype.setup = async function () { const schemaTemplatePath = path.join(this.templatePath, "schema.hbs"); let templateSource = await readFile(schemaTemplatePath); this.templateSchema = Handlebars.compile(templateSource.toString()); }; RendererMarkdown.prototype.renderSchema = function (data) { data.displaySchema = this.displaySchema;
3
6
2
40 41 42 43 44 45 46 47 48 49 50 51
arg.linkedName = arg.name; } } // let html = converter.makeHtml("**I am bold!**"); // let html = Handlebars.compile(); function md2html( file ){ file = file.substr( file.length - 3 ) === '.md' ? file : file + '.md'; // add extension if need be
3
3
15
107 108 109 110 111 112 113 114 115 116 117
}); } } function buildHTML(templateName, target, data) { var template = Handlebars.compile( fs.readFileSync( path.join(__dirname, 'views', templateName + '.handlebars'), 'utf8' )
1
2
1
+ 7 other calls in file
82 83 84 85 86 87 88 89 90 91
}); HandlebarsIntl.registerWith(Handlebars); // Handlebars.registerHelper("date") // Send all necessary resources to the handlebars template and compile it return Handlebars.compile(template)({ resume: resume, standardCSS: standardCSS, printCSS: printCSS, screenCSS: screenCSS
1
0
0
35 36 37 38 39 40 41 42 43 44
} catch (error) { console.error(`Failed to read character data for user ${userId}:`, error); } // Compile the Handlebars template to fill name/user into dialog sample let bd = JSON.stringify(bot.dialog) const template = Handlebars.compile(bd); // Fill in the variables with data from the bot object const botDialog = template(bot); // Prepare profile facts for prompt let facts = JSON.stringify(bot.fact)
0
1
3
+ 7 other calls in file
GitHub: schwabyio/xrun
794 795 796 797 798 799 800 801 802 803
} else { const collectionTemplate = data.toString() //preventIndent = true prevents indentation within partials (e.g. prevents unwanted indenting in <pre></pre> tags within partials) //https://github.com/handlebars-lang/handlebars.js/issues/858 const template = handlebars.compile(collectionTemplate, {noEscape: true, preventIndent: true}) const collectionHtmlResult = template(collectionResults) fs.writeFile(collectionHtmlPath, collectionHtmlResult, function resultOfWriteHtmlSummary(err) { if (err) {
0
1
1
+ 5 other calls in file
handlebars.compile is the most popular function in handlebars (550 examples)