Skip to content

Support for returning a complex object from a subexpression #264

Closed
dotnet/arcade
#16884

Description

@rmja

Hi,

In handlebars.js one can create a helper that returns a complex object to be used by other helpers like so:

Handlebars.registerHelper("now", () => {
    return new Date(); // Returns a complex object, not a string
});
Handlebars.registerHelper("format", (value) => {
    if (value instanceof Date) {
        // This is the complex Date object, format as date
        return Handlebars.SafeString(value.valueOf());
    else {
        // This is not a Date object
        return Handlebars.SafeString("not a date");
     }
});

In the template I have something like {{format (now)}}. This works in handlebars.js, but I cannot figure out how to do it in .NET land. I don't want to write (serialize) the object in now() and then deserialize it again in format().

Any suggestions?

Activity

  1. rexm commented on Aug 30, 2018

    @rexm
    Member

    This isn’t natively supported yet. Serialization would work.

  2. rexm commented on Apr 27, 2019

    @rexm
    Member

    This is something that needs to be supported, but the most obvious ways to do it would introduce breaking changes to 1.x, so it's a core part of planning for v2.

  3. added a commit that references this issue on Apr 23, 2020
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions