Handlebars.Net icon indicating copy to clipboard operation
Handlebars.Net copied to clipboard

Space required between block helper close and open tags

Open 206mph opened this issue 10 years ago • 4 comments

We found that this is causing the template to fail:

{{#is ProgramID ""}}no program{{/is}}{{#is ProgramID "1081"}}some program text{{/is}}

However, when we format it with a space between the block close tag and block open tag, it works.

{{#is ProgramID ""}}no program{{/is}} {{#is ProgramID "1081"}}some program text{{/is}}

Any ideas?

206mph avatar May 12 '16 20:05 206mph

I tried to reproduce this as best I can (I am not sure what the #is helper does, though I can guess) - and it seems to work fine. Can you provide more details? i.e. What does "fail" mean?

rexm avatar May 12 '16 20:05 rexm

The helper code: Handlebars.RegisterHelper("is", (writer, options, context, arguments) => { try { var current = arguments[0].NullSafeToString(); var compare = arguments[1].NullSafeToString(); if (current == compare) { options.Template(writer, (object)context); } else { options.Inverse(writer, (object)context); } } catch { //do something } });

When I call Handlebars.compile, it generates the error:

Non-empty collection required Parameter name: expressions

206mph avatar May 12 '16 21:05 206mph

Only two things I can think of that have made my test cases pass and someone else's fail:

  • Can you confirm that is the exact template you're testing?
  • Are you using Windows (I'm on Mac, every once in awhile they are slightly different)

rexm avatar May 12 '16 21:05 rexm

This is odd. I did a little more digging myself and can confirm that it works fine if my template has only the 2 "is" helpers with no space. I can't provide the whole template as my client might not be happy with me. I'll have to do more investigating to see what's causing the issue. Meanwhile, at least we have a workaround of adding the space between the helper close/open tags.

206mph avatar May 12 '16 22:05 206mph