Not every Go function is exposed for templates to use. Unless you’re using the browse directive, I don’t think we have one right now that you can use which would give you a list of files. However, that’s only for browse templates which sounds like isn’t really what you want – you just want to use the templates directive and have a way to get a list of files.
I don’t see why this would be a problem to implement – it shouldn’t be a security concern since the site owner creates the templates (I guess you could shoot yourself in the foot but this isn’t the only way).
Would you please be able to open an issue on GitHub to request this feature? It should be fairly straightforward to implement, I’m sure a new contributor would love to hack on it. Maybe even yourself!
Thanks for the answer. I posted a Github issue (https://github.com/mholt/caddy/issues/1198) as you suggested, and I will start digging in the sources to see if I can do it myself.