Is it possible to get response code in Caddy template?

There isn’t a whole lot of documentation as far as I can tell with Caddy templates, so I want to know if it’s possible to get response code in a Caddy template. So I can for example do

{{if .responsecode eq 404}}
<p>404 not found</p>
{{end}}

or whatever.

Templates are run before the status code is decided, so this doesn’t quite make sense.

Unless you mean the status code from an error, inside of handle_errors, in which case you can use the placeholder function to get the value of the http.error.status_code placeholder.

Please fill out the help topic template, as per the forum rules. There’s not enough context in your question so I have to make assumptions to answer, and that wastes time for the both of us.

Sorry, that’s a bug that will be fixed when v2.6.3 is released. :see_no_evil:

What’s a placeholder function? Never heard of that before. Also yeah, I should have filled the template, I’m sorry. But yes, that’s precisely what I want.

Unfortunately, the template docs are broken on the website, but it’ll be fixed in the next release. In the meantime, you can see the docs here:

2 Likes

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