[V2] KODI-compatible browse template

1. Caddy version (caddy version):


2. How I run Caddy:

a. System environment:

On Ubuntu 20.04 amd64, installed using the official repository.

b. Command:

systemctl restart caddy

c. Service/unit/compose file:

default from repo - systemd

d. My complete Caddyfile or JSON config:

root * /usr/share/caddy
file_server {
	browse /etc/caddy/browse.tpl

The browse.tpl template was apparently made for Caddy v1 and can be found here.

The alternate template used can be found here.

3. The problem I’m having:

Accessing the web server results in a blank page.

4. Error messages and/or full log output:

First browse template:

2020/05/24 21:44:25.281 ERROR http.log.error template: browse.tpl:223:39: executing “browse.tpl” at <.BreadcrumbMap>: can’t evaluate field BreadcrumbMap in type fileserver.browseListing {“request”: {“method”: “GET”, “uri”: “/”, “proto”: “HTTP/1.1”, “remote_addr”: “87.160.xxx.xxx:49887”, “host”: “141.164.54.xxx”, “headers”: {“Accept-Language”: [“en-US,en;q=0.5”], “Dnt”: [“1”], “Connection”: [“keep-alive”], “Upgrade-Insecure-Requests”: [“1”], “If-None-Match”: ["“q9tge59fm”"], “Accept”: [“text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8”], “Accept-Encoding”: [“gzip, deflate”], “If-Modified-Since”: [“Mon, 04 May 2020 16:56:29 GMT”], “Cache-Control”: [“max-age=0”], “User-Agent”: [“Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:76.0) Gecko/20100101 Firefox/76.0”]}}, “duration”: 0.000934518, “status”: 500, “err_id”: “bkyysr3jw”, “err_trace”: “fileserver.(*FileServer).serveBrowse (browse.go:80)”}

The second template results in the following error as soon as the browse folder isn’t empty:
"msg":"template: browse.tpl:27:33: executing \"browse.tpl\" at <$.Replace>: can't evaluate field Replace in type fileserver.browseListing"

5. What I already tried:

Browse without a template works fine

6. Links to relevant resources:

Browse plugin KODI/XBMC support - Thread used as reference

You can see the default template for Caddy v2 here:


First thing I notice is that BreadcrumbMap is now Breadcrumbs.

For the second error, I think you can replace

{{$.Replace (urlquery .Name) "+" "%20"}}{{if .IsDir}}/{{end}}

with {{html .URL}}

Let me know if you encounter any other errors.


@intramad is this resolved?

Thanks and sorry for the late response on my end. I have made it work using your suggestion. The template works now, but I don’t get the option to go into the above directory like I did with Caddy v1.

The template is:

  <title>Index of {{html .Path}}</title>
  <h1>Index of {{html .Path}}</h1>
    {{- if and (eq .Sort "name") (ne .Order "desc") -}}
    <a href="?sort=name&order=desc">
    {{- else -}}
    <a href="?sort=name&order=asc">{{end}}Name</a></th><th>
    {{- if and (eq .Sort "time") (ne .Order "desc") -}}
    <a href="?sort=time&order=desc">
    {{- else -}}
    <a href="?sort=time&order=asc">{{end}}Last modified</a></th><th>
    {{- if and (eq .Sort "size") (ne .Order "desc") -}}
    <a href="?sort=size&order=desc">
    {{- else -}}
    <a href="?sort=size&order=asc">{{end}}Size</a></th><th></th></tr>
    <tr><th colspan="5"><hr></th></tr>
    {{if .CanGoUp -}}
    <tr><td></td><td><a href="..">Up one level</a></td><td></td><td></td><td></td></tr>
    {{- end}}
    {{- range .Items}}
    <tr><td></td><td><a href="{{html .URL}}">
    {{- .Name}}{{if .IsDir}}/{{end}}</a></td><td align="right">
    {{- .HumanModTime "02-Jan-2006 15:04"}} </td><td align="right">
    {{- if .IsDir}}-{{else}}{{.HumanSize}}{{end}}</td><td></td></tr>
    {{- end}}
    <tr><th colspan="5"><hr></th></tr>
  <address>caddy server</address>

You mean this bit doesn’t appear?

That’s strange, I see CanGoUp is still a thing in the browseListing struct, so that should work as far as I can tell.

Exactly, I get a blank line 11 as opposed to:

<tr><td></td><td><a href="..">Up one level</a></td><td></td><td></td><td></td></tr>
on Caddy v1.

I’ll doublecheck this on an entirely blank Caddy instance first though.

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