Using {{else}} seems misleading to me


#1

When I first saw below construct I immediately thought that depending on the ‘person’ condition either ‘Content Block’ or ‘Else Block’ will be “executed” - that is used inside the template.

But as it turns out these two block are ALWAYS given to the template and ‘person’ is not condition in any way. Instead person is just a parameter and it is up to specific template implementation to decide what to do with this parameter and how to apply it to Content and Else blocks. I find this to be very confusing syntax that looks like something that it is not.

So my question would be why this looks like it does? Am I missing something? Why is term “else” used?

Why instead we don’t have ability to define more of these blocks which are actually nothing more then parameters - each containing a block of HTML. Currently we are limiting number of HTML code parameters that Block Template can take to two parameters? This would be like having functions in JavaScript that can take maximum of two parameters. Why not, instead of {{else}} have something like {{param1}}, {{param2}}, etc.

Also this {{else}} looks like reference to helper? Is it? If it is not but it looks like it is that is also very confusing.

  {{#myTemplate person}}
    Content Block
  {{else}}
    Else Block       
  {{/myTemplate}}

#2

Yes. It’s something confusing but how to use elseBlock totally upto the template. This is built to allow to write more utility functions like if.

For an example, you can have a loading indicator like this.

{{#loading millisToWait=5000}}
  {{>myHomePage}}
{{else}}
  Loading ...
{{/loading}}

You don’t need to write an else content. Then, it’ll use it’s default loading indicator. We can override with the something we put into the else block.

Anyway, I also think else is not the best word for this purpose. But, after once you realized it’s meaning, this is something very useful.