Skip to content

Support for returning a complex object from a subexpression #264

@rmja

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?

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