Use external YAML data for rendering a template

Hi,

Is there a way to include an arbitrary file, in my case YAML, that will be read and made available when caddy is rendering templates? I have an app that keeps all it’s config data in a flat YAML file and I’d like to build a simple website that let’s me look at that data in a friendly way. If caddy just imported that YAML file then made it available to the templates that’d make this easy to do, but looking at the templates docs I don’t see an obvious way to get a large amount of structured external data in for the rendering. Also the data is constantly changing so caddy needs to re-read the file whenever it is updated to show the latest data.

Alternatively am I thinking about this the wrong way and there is a better solution I’m not seeing?

Thanks,

griznog

I’m not totally sure I follow, no. Can you use YAML front-matter for this? You can use the splitFrontMatter function for that.

Maybe you need to implement your own custom template function, which you can do as a Caddy plugin. It could load your YAML file & parse it then add it as variables in the template context.

2 Likes

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