Templates not working for me? Probably driver error

With the V2 built from github on a Mac.

Including the templates directive in the Caddyfile, I get no html output from my sample web site - it’s all
static pages.

Are them some examples out there of a web site using templates?

Thanks,

Joe

Please post your full Caddyfile, we can’t help you without knowing what you’ve tried.

The thread template is there to help both you and us. Make sure to fill it out instead of deleting it!

http://127.0.0.1:4000 {
root * /Users/joe/caddy/public_html
log {
output file http.log
}
file_server
templates
}
~

Would you be able to supply a minimal index file that shows this behaviour?

Also helpful information:

  • Version (run caddy version and copy output)
  • How you run Caddy (which command / as a service / etc)
  • Which requests you made, and any log output from those requests
1 Like

INDEX.HTML:

MINIMAL WEB PAGE

{{.IP}}

CADDYFILE:
http://127.0.0.1:4000 {
root * /Users/joe/caddy/public_html
log {
output file http.log
}
file_server
templates
}
…/caddy version

(devel)

This is really frustrating as I can’t even get the small example from the Caddy V2 documentation working.
I just get a blank page returned with nothing in it if I look at the page source.

I noticed this from the log:
status": 500, “err_id”: “5vtpj8ve5”, “err_trace”: “templates.(*Templates).executeTemplate (templates.go:292)”}

Byw, is there a way to shorten the size of each log entry, or can I pick & choose which bits of data get logged?

Thanks,

Joe

It errors out because there’s no data element with the name .IP to be included in template execution context. The list of available data and functions is listed here in the JSON docs. I believe you’re looking for {{.RemoteIP}}.

In regards to logging, you might be interested in the single_field option.

3 Likes

Ahh! Success! Thanks Mohammed for the hint.

Joe

Also, in the wiki, @nicolinux has written a really handy guide for using jq to parse Caddy’s log output to your liking.

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