V2 - http.handlers.templates functions in file_server browse template?

I recently came across documentation for the http.handlers.templates module, and I was hoping that I would be able to use these functions in a template for file_server browse, but I’ve found that they don’t seem to be available. I tried adding {{ httpInclude "README.html" }} to the browse template but then Caddy would exit on startup because the httpInclude function wasn’t found. The reason why I’d like to be able to use httpInclude in browse templates is because I want to have a description under the file listing, like how ftp.debian.org includes the contents of README.html when you are looking at the file listing of a directory.

Hmm. Yeah I would think that should work.

Did you try adding the templates directive to your Caddyfile as well? It essentially acts like a filter after the fact. Not sure if it’ll work, but it might.

Yes, this is the Caddyfile that I’m using:

:2015

templates
file_server {
    browse template.html
}

and the contents of template.html:

<!DOCTYPE html>
<html>
        <head>
        <body>
                {{ httpInclude "readme.html" }}
        </body>
</html>

caddy run yields the error function "httpInclude" not defined on both revision v2.0.0 and latest master.

Probably an oversight on my part – not looking at the code right now but I bet we don’t initialize the same template functions in browse as we do in the templates middleware. Shouldn’t be hard to do though.

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