JSFiddle - React, Tailwind, and code Playground

handlebars helpers

by Laurens Maneschijn

JavaScript

// https://cdnjs.com/libraries/handlebars.js/
// https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/3.0.3/handlebars.min.js (written using this)
// https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.7.6/handlebars.min.js (current latest 2020-06-02)
var handlebars;

// TODO add usage examples

// http://stackoverflow.com/questions/11924452/handlebar-js-iterating-over-for-basic-loop
handlebars.registerHelper('for', function(from, to, block) {
	var accum = '';
	for(var i = from; i <= to; i++)
		accum += block.fn(i);
	return accum;
});

			handlebars.registerHelper ("ifEquals", function (value, currentValue, options) {
				if (value == currentValue) {
					return options.fn(this);
				}
				return options.inverse(this);
			});

			// Source: http://stackoverflow.com/a/16315366
			// Example usage: {{#ifCond var1 '==' var2}}
			handlebars.registerHelper('ifCond', function (v1, operator, v2, options) {
				switch (operator) {
					case '==':
						return (v1 == v2) ? options.fn(this) : options.inverse(this);
					case '===':
						return (v1 === v2) ? options.fn(this) : options.inverse(this);
					case '!=':
						return (v1 != v2) ? options.fn(this) : options.inverse(this);
					case '!==':
						return (v1 !== v2) ? options.fn(this) : options.inverse(this);
					case '<':
						return (v1 < v2) ? options.fn(this) : options.inverse(this);
					case '<=':
						return (v1 <= v2) ? options.fn(this) : options.inverse(this);
					case '>':
						return (v1 > v2) ? options.fn(this) : options.inverse(this);
					case '>=':
						return (v1 >= v2) ? options.fn(this) : options.inverse(this);
					case '&&':
						return (v1 && v2) ? options.fn(this) : options.inverse(this);
					case '||':
						return (v1 || v2) ? options.fn(this) : options.inverse(this);
					default:
						bs_raven.message('ifCond operator not recognised: ' + operator, this_module.id, 'init: handlebars.registerHelper ifCond', raven_tag);
						return...