Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is is possible to provide helpers when the template is being rendered? #558

Open
markdebhailis opened this issue Oct 23, 2023 · 1 comment
Labels

Comments

@markdebhailis
Copy link

markdebhailis commented Oct 23, 2023

Using this sample as a reference https://github.com/Handlebars-Net/Handlebars.Net#registering-helpers

I would like to pass the helper implementation to the template e.g. here's some psuedo code

string source = @"Click here: {{link_to}}";

var template = Handlebars.Compile(source);

HandlebarsHelper link_to = "link_to", (writer, context, parameters) => 
{
    writer.WriteSafeString($"<a href='{context["url"]}'>{context["text"]}</a>");
};

var data = new {
    url = "https://github.com/rexm/handlebars.net",
    text = "Handlebars.Net",
    link_to = link_to
};

var helpers = new {
    link_to = x)
};

var result = template(data);

The above outputs Click here: HandlebarsDotNet.HandlebarsHelper but I want it to recognise that 'link_to' is a helper.

I know it's possible to register the helper after the template is compiled but I want to be able scope the function to a single template render operation.

@oformaniuk
Copy link
Member

No, it is not possible at the moment. I'd be happy to see PR enabling such behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants