eta icon indicating copy to clipboard operation
eta copied to clipboard

Inject Methods/Object with Plugins

Open shadowtime2000 opened this issue 5 years ago • 2 comments

Is your feature request related to a problem? Please describe. Currently there isn't a nice clean way to inject methods or objects with plugins for usage in the template.

Describe the solution you'd like Some way to inject methods for usage.

Additional context Carrying over discussion from Gitter, we could allow modification of prototype (I don't think that works), allowing injecting into this of template, or use some scoping tricks with dynamic closures to handle this (still thinking about it).

shadowtime2000 avatar Dec 08 '20 04:12 shadowtime2000

Possible usage:

module.exports = {
	injectThis: (config) => {
		return {
			add: (a, b) => a + b
		}
	}
}
<%= this.add(2, 3) %>

shadowtime2000 avatar Dec 08 '20 04:12 shadowtime2000

I'd really need this as well for e.g. global translation methods 👍🏻

lenovouser avatar May 12 '21 13:05 lenovouser

@shadowtime2000 any updates or way one can help out with this?

lenovouser avatar Nov 27 '22 16:11 lenovouser