Skip to content

Add ability to unregister helpers #724

@Lepidopteran

Description

@Lepidopteran

Hello,

First of all this is an awesome project, I've been using to add template support to one of my projects!

However I noticed I'm not able to to unregister helpers and in addition script_helpers.

I was wondering if there a is a certain reason for this behavior?

The reason why I want to be able to unregister helpers is I want to use script_helpers to add the ability to modify values for certain templates the user could write, but I believe the only way to register a script_helper or helper is to register it globally to the Handlebars struct.

I took a quick look at the code for the registry module:

/// Register a helper
pub fn register_helper(&mut self, name: &str, def: Box<dyn HelperDef + Send + Sync + 'reg>) {
self.helpers.insert(name.to_string(), def.into());
}

It looks like it just adds the boxed HelperDef trait to a HashMap, so couldn't there be a function like the following that does the opposite?:

/// Unregister a helper
pub fn unregister_helper(&mut self, name: &str) {
    self.helpers.remove(name);
}

I would be happy to create a pull request if this is and acceptable solution.

If this feature doesn't get added I don't mind, as I believe I can just clone the Handlebars struct in rendering function of my project then register the helpers so it creates a temporary registration, though I haven't tested this solution yet.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions