JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://raw.github.com/wycats/handlebars.js/1.0.0/dist/handlebars.js"></script>
<script type='text/template' id='src'>
{{#ifor firstname lastname}}
<p>
{{#if firstname}}
<span class="firstname">{{firstname}}</span>
{{/if}}
{{#if lastname}}
<span class="lastname">{{lastname}}</span>
{{/if}}
</p>
{{else}}
Nope
{{/ifor}}
</script>
CSS
p {background: green; color: white}
JavaScript
Handlebars.registerHelper('ifor', function() {
var l, opts;
opts = Array.prototype.pop.call(arguments);
for (l = arguments.length-1; l>=0; l--) {
//if (typeof(arguments[l])==='undefined')
if (arguments[l])
return opts.fn(this);
}
return opts.inverse(this);
});
var tpl = Handlebars.compile($('#src').html());
$('body').append(tpl({
firstname: 'first'
}));
$('body').append(tpl({
}));
$('body').append(tpl({
firstname: 'first',
lastname: 'last'
}));