caddyserver/caddy · error
delimiters must consist of exactly two elements: opening and
Error message
delimiters must consist of exactly two elements: opening and closing
What it means
Returned by Templates.Validate when the 'delimiters' field is set but does not have exactly two elements (opening and closing). The check allows only the zero-value (unset) or a two-element array; anything else is rejected at config validation time before serving.
Source
Thrown at modules/caddyhttp/templates/templates.go:433
return fmt.Errorf("loading template extensions: %v", err)
}
for _, modIface := range mods.(map[string]any) {
t.customFuncs = append(t.customFuncs, modIface.(CustomFunctions).CustomTemplateFunctions())
}
if t.MIMETypes == nil {
t.MIMETypes = defaultMIMETypes
}
if t.FileRoot == "" {
t.FileRoot = "{http.vars.root}"
}
return nil
}
// Validate ensures t has a valid configuration.
func (t *Templates) Validate() error {
if len(t.Delimiters) != 0 && len(t.Delimiters) != 2 {
return fmt.Errorf("delimiters must consist of exactly two elements: opening and closing")
}
return nil
}
func (t *Templates) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error {
buf := bufPool.Get().(*bytes.Buffer)
buf.Reset()
defer bufPool.Put(buf)
// shouldBuf determines whether to execute templates on this response,
// since generally we will not want to execute for images or CSS, etc.
shouldBuf := func(status int, header http.Header) bool {
ct := header.Get("Content-Type")
for _, mt := range t.MIMETypes {
if strings.Contains(ct, mt) {
return true
}
}View on GitHub (pinned to 50e54ee279)
Solutions
- Set exactly two delimiters, opening then closing: delimiters [[[ ]]]
- Remove the delimiters field entirely to use the defaults {{ and }}
- Validate the config before deploying with `caddy validate --config <file>`
- Check for accidental extra tokens/args in the Caddyfile block
Example fix
# before
templates {
delimiters [[[ ]]] ]]
}
# after
templates {
delimiters [[[ ]]]
} Defensive patterns
Strategy: validation
Validate before calling
caddy validate --config Caddyfile # Validate() rejects bad delimiter counts before serving
Prevention
- Always supply delimiters as a pair (open, close)
- Run caddy validate in CI to catch structural config errors
- Prefer default {{ }} delimiters unless the content genuinely conflicts
When it happens
Trigger: Configuring the templates handler with a delimiters array of length 1, 3, or more; e.g. providing only an opening delimiter like [[[ without a matching ]]], or accidentally listing three strings.
Common situations: Hand-editing JSON config where delimiters is an array, copying Go's template syntax expectations into Caddy config, or a Caddyfile like `templates { delimiters [[ ]] }` where a stray token makes three args.
Related errors
- root file system not specified
- parsing environment file: %v
- can't parse line %d; line should be in KEY=VALUE format
- missing or empty key on line %d
- invalid key on line %d: contains whitespace: %s
AI-assisted analysis of caddyserver/caddy@50e54ee279 (2026-08-15).
Data as JSON: /api/errors/9c2090a0c89eb972.
Report an issue: GitHub.