Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 11, 17:15 UTC
docs: add maybe template function documentation (#7388)
Steffen Busch committed
Dec 6, 2025 at 12:51 UTC
bfdb04912d26e367986984ec435a7879a817614f
1 file changed
+22
-4
modules/caddyhttp/templates/templates.go
+22
-4
@@ -306,6 +306,13 @@ func init() {
306
// find the documentation on time layouts [in Go's docs](https://pkg.go.dev/time#pkg-constants).
307
// The default time layout is `RFC1123Z`, i.e. `Mon, 02 Jan 2006 15:04:05 -0700`.
308
//
309
+// ```
310
+// {{humanize "size" "2048000"}}
311
+// {{placeholder "http.response.header.Content-Length" | humanize "size"}}
312
+// {{humanize "time" "Fri, 05 May 2022 15:04:05 +0200"}}
313
+// {{humanize "time:2006-Jan-02" "2022-May-05"}}
314
+// ```
315
+//
316
// ##### `pathEscape`
317
//
318
// Passes a string through `url.PathEscape`, replacing characters that have
@@ -318,11 +325,22 @@ func init() {
325
// {{pathEscape "50%_valid_filename?.jpg"}}
326
// ```
327
//
328
+// ##### `maybe`
329
+//
330
+// Invokes a custom template function only if it is registered (plugged-in)
331
+// in the `http.handlers.templates.functions.*` namespace.
332
+//
333
+// The first argument is the function name, and any subsequent arguments
334
+// are forwarded to that function. If the named function is not available,
335
+// the invocation is ignored and a log message is emitted.
336
+//
337
+// This is useful for templates that optionally use components which may
338
+// not be present in every build or environment.
339
+//
340
+// NOTE: This function is EXPERIMENTAL and subject to change or removal.
341
+//
342
// ```
322
-// {{humanize "size" "2048000"}}
323
-// {{placeholder "http.response.header.Content-Length" | humanize "size"}}
324
-// {{humanize "time" "Fri, 05 May 2022 15:04:05 +0200"}}
325
-// {{humanize "time:2006-Jan-02" "2022-May-05"}}
343
+// {{ maybe "myOptionalFunc" "arg1" 2 }}
344
// ```
345
type Templates struct {
346
// The root path from which to load files. Required if template functions