Combining "templates" and "static_response" or inline templates

Hi, I don’t think I’m fully grasping the concept of templates in Caddy yet. I have extensive experience with templates generally.

Question 1: Is it possible to combine “templates” and “static_response”?

Question 2: is it possible to have inline templates instead of having them in a separate file?

Ideally I would like to have a simple “hello world” type example where the “hello world” text came from a simple inline template.

Thank you

Yes! The static response can consist of a template string which will then be evaluated.

I believe so:

Don’t forget to set the right Content-Type of your static response.

Caddyfile example:

:80 {
	respond `This is a template: {{ placeholder "system.hostname" }}`
$ curl http://localhost
This is a template: francis-laptop

Thank you all so much, I’ve managed to do a simple PoC that shows that what I want to do is possible. Kudos!


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.