Handlebars-Net/Handlebars.Net

[Question] Are multiple formatters for the same type supported in some way?

Sacrilege opened this issue · 1 comments

A example scenario would be a class that has 2 different DateTime properties where one should be rendered using the date and time and one should be rendered only using the date. Is there some way to tell handlebars to use a different formatter for each property?

Hello @Sacrilege,

There's basically two options:

  • Explicitly define format in the template using helper
  • Implement IObjectDescriptorProvider and IMemberAccessor for your type and return already formatted string for those properties.
    An advanced variation of this would be to implement a generic wrapper that would know how to format containing value as well as accessing its properties.

Unfortunately defining custom format on property declaration (via attribute) is not supported and assuming current design it is complicated to implement something like this.