Caddy templates: a way to test if a file is a directory?

Is there a way, in a Caddy template to test if a file is a directory or an ordinary file ? I use listFiles in a loop and want different behavior for each entry depending on whether it is a regular file or a folder.

I googled it for a while and did not found useful answers…

I don’t think there is right now. The only built-ins are essentially things that we needed to build the Caddy website and from feature requests on GitHub. Seems like an oversight.

You could add it yourself with a plugin in the namespace http.handlers.templates.functions.*, implementing the CustomFunctions interface.

Or you could propose a change on GitHub (source is in caddy/tplcontext.go at master · caddyserver/caddy · GitHub)

Thanks for your help. I proposed the addition here as I may be useful to others.

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