Skip to content

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

Closed

Description

@Sacrilege

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?

Activity

  1. oformaniuk commented on Feb 1, 2021

    @oformaniuk
    Member

    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.

  2. locked and limited conversation to collaborators on Feb 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions