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

  1. Set exactly two delimiters, opening then closing: delimiters [[[ ]]]
  2. Remove the delimiters field entirely to use the defaults {{ and }}
  3. Validate the config before deploying with `caddy validate --config <file>`
  4. 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

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


AI-assisted analysis of caddyserver/caddy@50e54ee279 (2026-08-15). Data as JSON: /api/errors/9c2090a0c89eb972. Report an issue: GitHub.