Kodi compatible browse template (again2)

1. Output of caddy version:


2. How I run Caddy:

caddy run

a. System environment:

debian 11

b. Command:


c. Service/unit/compose file:


d. My complete Caddy config:

my.domain {
        root * /disk/whatever/
        file_server * {
                browse /etc/caddy/simple.html
                # browse

3. The problem I’m having:

Caddy seems exactly what i need for Kodi, to access my media files across the Internet via https with username/password authentication

Unfortunately, caddy’s browsing (directory listing) output is not compatible with Kodi (19.4 in my case).

There where two prior threads about this issue of cady with kodi, but i could not see that either of them resolved the issue.

Kodi understands the output of lighttpd. the most easy solution would be for caddy to support a browse file that would provide lighttpd output.

I tried to copy the lighttpd output and program it in this caddy ?macro? langauge with {{}}. Looks mostly like this: (simple.html):

<table summary="Directory Listing" cellpadding="0" cellspacing="0">
<thead><tr><th class="n">Name</th><th class="m">Last Modified</th><th class="s">Size</th><th class="t">Type</th></tr></thead>
{{range .Items}}
  <tr class="d">
    <td class="n"><a href="{{html .Name}}">{{html .Name}}</a></td>
    <td class="m">{{.HumanModTime "2006-Jan-02 15:04:05"}}</td>
    <td class="s">{{.HumanSize}}</td>
    <td class="t">{{- if .IsDir}}Directory{{- else}}application/octet-stream{{- end}}</td>

Question 1: What is the ?macro/scripting? system that caddy uses for browse files, e.g.: what is all the syntax available via {{ … }} ? I could not find this information in the caddy documentation.

There are i think two main issues emulating output that kodi understands.

  1. The URL of an element in the directory:

1.a When i use:

{{html .URL}}

then caddy will create a URL starting with “./” that Kodi fails to parse (result: Kodi shows empty directory)

1.b When i use

{{html .Name}}

Kodi can parse the result, but it does (of course) not work for names that include spaces (and maybe other characters that need special HTML/URL mapping). One of the prior threads here in the forum included some {{$.Replace }} command thart might help, but i couldn’t get it to do anything but for caddy to just not render any output. Hence my question 1 (where can i find documentation for what i can do with caddy’s {{}}).

  1. {{.HumanSize}}

Kodi is disgustingly narrow-minded in the format it can parse for the size of an entry:
XX.X[GKM], whereas caddy’s .HumanSize renders XX GiB for example, eg.: with a space and with “GiB” instead of “G”. So .HumanSize is not recognized by Kodi, resulting in zero element size recognized by Kodi.

Again, this may be something one could maybe work around with some series of textual output substitutions… if i could not find documentation.

Question 2: If caddy’s html ?macro? langauge with {{}} can not get the job done, how would i mostly easily be able to configure caddy so that directory output would be taken from running a unix program/script ?

Thank you so much

4. Error messages and/or full log output:

5. What I already tried:

6. Links to relevant resources

​ ​ ​ ​

1 Like

The docs do mention it, it’s a “template”. The file_server docs link to this page which explains everything you need to know. The template system is provided by Go, and we add on a bunch of extra functions to make it more useful in the context of Caddy.

I think it should definitely be possible purely with the templates, but I’m not sure I can do much to help; maybe @matt might be able to chime in on some of the rest.

Do you have a link to the Kodi docs that describe the format it expects?

1 Like

Yeah, I’m not sure what to tell ya. Maybe some sprig functions (see the “strings” page) could help do substring replacements: String Functions | sprig

1 Like


I am not aware of any documentation for what Kodi expects.
The string functions did do the trick it seems.

1 Like

Please document what template did work for you in the end, in case someone else comes along and finds this thread in the future!


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