The Wayback Machine - https://web.archive.org/web/20220517012312/https://github.com/caddyserver/caddy/issues/4568
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

Make templates pluggable #4568

Closed
francislavoie opened this issue Feb 10, 2022 · 2 comments · Fixed by #4757
Closed

Make templates pluggable #4568

francislavoie opened this issue Feb 10, 2022 · 2 comments · Fixed by #4757
Labels
feature good first issue

Comments

@francislavoie
Copy link
Member

@francislavoie francislavoie commented Feb 10, 2022

Context: https://caddy.community/t/including-files-scripts/15050/4

Right now, the templates module is inflexible in that only functions the functions registered by Caddy itself are available.

A good refactor would be to make it possible to pass an optional array of modules in the http.handlers.templates.functions.* namespace which get invoked at Provision() time to register additional functions.

@kroppt
Copy link
Contributor

@kroppt kroppt commented Apr 30, 2022

I am interested in working on this.

The TemplateContext is responsible for parsing and executing templates. It knows which functions are valid. It's a part of the http.handlers.templates module. That module then must get custom functions at Provision time for hand-off to that context.

Modules would be defined under http.handlers.templates.functions (e.g. http.handlers.templates.functions.bash) which allows for a definition of how to execute the function (e.g. call exec.Command with bash and the script filepath). Adding new function types can be done by adding a module under http.handlers.templates.functions.*, which can be added to a server as a Caddy plugin.

Is my understanding of the problem correct?

@francislavoie
Copy link
Member Author

@francislavoie francislavoie commented Apr 30, 2022

Yep, that's right!

I think you can use caddy.GetModules("http.handlers.templates.functions") to fetch a list of all the registered modules in that namespace, and if they conform to the right interface, you can load them in.

func GetModules(scope string) []ModuleInfo {

That way, plugging in new functions would be zero-config, they would just added in if they're registered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature good first issue
2 participants