How to use the registerHelper function from handlebars
Find comprehensive JavaScript handlebars.registerHelper code examples handpicked from public code repositorys.
GitHub: GetPublii/Publii
427 428 429 430 431 432 433 434 435 436
let helperNames = Object.keys(HandlebarsHelpers); // Register all helpers for(let helperName of helperNames) { if(helperName.substr(-6) !== 'Helper') { Handlebars.registerHelper( helperName, HandlebarsHelpers[helperName] ); } else {
341
0
79
+ 5 other calls in file
GitHub: cliss/camel
414 415 416 417 418 419 420 421 422 423
}); loadHeaderFooter('postHeader.html', function (data) { Handlebars.registerHelper('formatPostDate', function (date) { return new Handlebars.SafeString(new Date(date).format('{Weekday}, {d} {Month} {yyyy}')); }); Handlebars.registerHelper('formatIsoDate', function (date) { return new Handlebars.SafeString(typeof(date) !== 'undefined' ? new Date(date).iso() : ''); }); postHeaderTemplate = Handlebars.compile(data); });
55
265
27
+ 5 other calls in file
GitHub: postalsys/emailengine
399 400 401 402 403 404 405 406 407 408
return new handlebars.SafeString(translated); }); handlebars.registerHelper('ngettext', (msgid, plural, count) => util.format(gt.ngettext(msgid, plural, count), count)); handlebars.registerHelper('equals', (compareVal, baseVal, options) => { if (baseVal === compareVal) { return options.fn(this); // eslint-disable-line no-invalid-this } return options.inverse(this); // eslint-disable-line no-invalid-this
113
0
16
+ 27 other calls in file
57 58 59 60 61 62 63 64 65
}; var registerFunctions = function(helperFunctions) { if(helperFunctions) { _.forOwn(helperFunctions, function(fn, key) { handlebars.registerHelper(key, fn); }); } };
21
0
1
+ 3 other calls in file
GitHub: Huawei/Huawei_CCA_TFA
98 99 100 101 102 103 104 105 106 107
/* * Register a helper to return a restructured version of the commit groups that includes commits * categorized by their section. */ Handlebars.registerHelper("tf-a-commits", function (commitGroups, options) { const generateTemplateData = function (sections, commits) { return (sections || []).flatMap(section => { const templateData = { title: section.title,
2
2
0
45 46 47 48 49 50 51 52 53 54
return v1 || v2; } }); // http://stackoverflow.com/a/18831911 Handlebars.registerHelper('commalist', function(items, options) { return options.fn(items.join(', ')); }); // Handlebars.registerHelper('formatdate', function(text) {
1
0
0
+ 2 other calls in file
GitHub: schwabyio/xrun
780 781 782 783 784 785 786 787 788 789
if(level >= handlebars.logger.level) { //console.log.apply(console, [].concat(["Handlebars: "], _.toArray(arguments))); console.log.apply(console, arguments) } } handlebars.registerHelper('log', handlebars.logger.log) // Std level is 3, when set to 0, handlebars will log all compilation results handlebars.logger.level = 0 //Read collectionTemplatePath
0
1
1
+ 20 other calls in file
76 77 78 79 80 81 82 83 84 85
); }*/ return md; } function default_1(theme) { Handlebars.registerHelper("toc", function () { var _a, _b, _c, _d; const md = []; const { hideInPageTOC } = theme; const isVisible = (_a = this.groups) === null || _a === void 0 ? void 0 : _a.some((group) => group.allChildrenHaveOwnDocument());
0
1
4
+ 3 other calls in file
GitHub: openactive/models-lib
22 23 24 25 26 27 28 29 30
get includeInheritedFields () { return true; } setupHandlebars() { Handlebars.registerHelper("renderMemberName", function() { return new Handlebars.SafeString(/^[A-Za-z0-9]*$/.test(this.memberName) ? this.memberName : `'${this.memberName}'`); }); }
4
0
8
+ 13 other calls in file
85 86 87 88 89 90 91 92 93 94 95
}) ) } function registerHelpers (src) { handlebars.registerHelper('resolvePage', resolvePage) handlebars.registerHelper('resolvePageURL', resolvePageURL) return vfs.src('helpers/*.js', { base: src, cwd: src }).pipe( map((file, enc, next) => { handlebars.registerHelper(file.stem, requireFromString(file.contents.toString()))
2
0
2
+ 5 other calls in file
GitHub: mrvautin/squido
241 242 243 244 245 246 247 248 249 250 251 252
// Check for helpers in the config if(process.config.templateConfig && process.config.templateConfig.helpers){ helpers = Object.assign(process.config.templateConfig.helpers, helpers); } handlebars.registerHelper(helpers); }; const runPlugins = async () => { for(const i in process.config.plugins){
7
48
3
GitHub: Jpleseux/projeto-meu-blog
91 92 93 94 95 96 97 98 99 100
app.use(bodyparser.urlencoded({extended: true})) app.use(bodyparser.json()) //handlebars app.engine('handlebars', handlebars.engine({defaultLayout: 'main'})) app.set('view engine', 'handlebars') Handlebars.registerHelper('error_', function (message) { return new Handlebars.SafeString(`<div class="error">${message}</div>`); }); Handlebars.registerHelper('ifCond', function(v1, operator, v2, options) { switch (operator) {
0
0
1
+ 5 other calls in file
GitHub: Dinesh6242/clone12
96 97 98 99 100 101 102 103 104 105 106
* Helper for creating translatable phrases * * {{ translate 'key.subkey' [string1 string2 ...] }} */ function translateHelper(rendererInstance, Handlebars) { Handlebars.registerHelper('translate', translate.bind(rendererInstance)); } module.exports = { translateHelper: translateHelper,
0
0
1
+ 5 other calls in file
110 111 112 113 114 115 116 117 118 119 120
const partialTypes = ["Card", "Title", "InfoBand"] let precompiledPartials = {} partialTypes.forEach(function (value, index, array) { handlebars.registerHelper('whichPartial'+value, function(context, options) { return context.data.root['entity']+value }) })
0
0
1
39 40 41 42 43 44 45 46 47
} return accum; }); // Add Handlebars.registerHelper('inc', (number, options) => { if (typeof (number) === 'undefined' || number === null) { return null; }
0
0
1
+ 71 other calls in file
GitHub: pestoura/Apache-Ambari
27 28 29 30 31 32 33 34 35 36
* * - If returning HTML use return new Handlebars.SafeString(); * - If the helper needs optional arguments use the "hash arguments" * Eg. {{{link . "See more..." story.url class="story"}}} * NOTE: the first argument after the helper name should be . which will be context in the helper function * Handlebars.registerHelper('link', function(context, text, url, options) { * var attrs = []; * * for(var prop in options.hash) { * attrs.push(prop + '="' + options.hash[prop] + '"');
0
0
1
+ 59 other calls in file
93 94 95 96 97 98 99 100 101
} }); Handlebars.registerHelper('json', function(context) { return JSON.stringify(context); }); Handlebars.registerHelper('ifEquals', function(arg1, arg2, options) { return (arg1 == arg2) ? options.fn(this) : options.inverse(this); }); }
0
0
2
+ 23 other calls in file
2 3 4 5 6 7 8 9 10 11
const Handlebars = require('handlebars'); const _ = require('lodash'); const pagesDirectory = "pages"; const output = "site"; (async () => { Handlebars.registerHelper('empty', function (value, options) { if (!value) { return options.fn(this); } return value.replace(/\s*/g, '').length === 0 ? options.fn(this) : options.inverse(this);
0
0
2
+ 2 other calls in file
6765 6766 6767 6768 6769 6770 6771 6772 6773 6774
// generate PDF process here if ('isPdfRequest' in queryData && queryData.isPdfRequest && bookingData.length > 0) { const htmlTemplate = reportTemplate.report_template; await Handlebars.registerHelper('ifCond', (lvalue) => { lvalue = parseInt(lvalue); if (lvalue % 25 == 0) { return true; } return false; });
0
0
1
+ 35 other calls in file
230 231 232 233 234 235 236 237 238 239
require.resolve('@appium/base-driver/lib/protocol/routes.js'), 'utf8' ); const routesFileLines = routesFile.split('\n'); Handlebars.registerHelper('spec_url', function specUrl(specUrl, endpoint) { // return the url if it is not a link to our routes doc if (!specUrl.includes('routes.js')) { return specUrl; }
0
0
1
+ 2 other calls in file
handlebars.compile is the most popular function in handlebars (550 examples)