tildeio / htmlbars

A variant of Handlebars that emits DOM and allows you to write helpers that manipulate live DOM nodes
MIT License
1.61k stars 193 forks source link

How to define an “if else” helper #471

Open R2D221 opened 7 years ago

R2D221 commented 7 years ago

Hi, I've recently found this project and I think it's an interesting alternative to Handlebars.

I'm testing some stuff to see how it works, but I can't find the way to set an “if else” helper. Normally in Handlebars this helper is already defined, but its documentation still shows you how it works.

Handlebars.registerHelper('if', function(conditional, options) {
  if(conditional) {
    return options.fn(this);
  } else {
    return options.inverse(this);
  }
});

However, in HTMLBar the API to define helpers is different. You invoke this.yield(); instead. But I can't find a way to tell the yield method to call the else block.

Am I doing something wrong, or is this feature not supported?