Handlebars-Net / Handlebars.Net.Helpers

Handlebars.Net helpers in the categories: 'Boolean', 'Constants', 'Enumerable', 'Environment', 'Math', 'Regex', 'String', 'DateTime' and 'Url'.
MIT License
40 stars 15 forks source link

Register helpers that return a boolean as 'usage: HelperUsage.Block' by default? #92

Closed SamGorbo closed 5 months ago

SamGorbo commented 5 months ago

Question

Hi! I just came across the library and am interested in using it for some projects. I first came to use the string comparison tools, and found that the only block scoped string comparison method is the Regex matching helper. Is there a reason why other methods that return booleans are not registered as HelperUseage.Block?

I would love to be able to write

{{#String.Equals name 'Bob'}}
  Message for just bob
{{/String.Equals}}

or

{{#String.Equals name 'Bob'}}
  Message for just bob
{{else}}
  Message for not bob
{{/String.Equals}}

I am trying to make some tooling for less technical individuals, and I think the better naming of some of the string methods would increase clarity. Is there a technical limitation? If not, I am happy to make a PR.

StefH commented 5 months ago

It's named String.Equal: https://github.com/Handlebars-Net/Handlebars.Net.Helpers/blob/63ec144b6bd6f2000506d0c46af339c04b9cc9f7/test/Handlebars.Net.Helpers.Tests/Templates/StringHelpersTemplateTests.cs#L74

Maybe it's a good idea to also add a method Equals. You can make a PR (code + unit tests) if you like.

SamGorbo commented 5 months ago

@StefH Ahh I understand. I don't think I fully understood how handlebars worked either. I didn't realize you could do

{{#if (String.Equal ...)}} {{/if}}

I apologize for wasting your time. Thanks for the wonderful library!