Skip to content

template

template captures the response body from the next middleware and replaces it with a rendered template.

yaml
server:
  http:
    middlewares:
      html_template:
        template:
          raw_body: true
          headers:
            Content-Type: text/html; charset=utf-8
          template: |
            <html><body>{{ .body_raw | codec.ByteToString }}</body></html>

Fields

FieldDefaultDescription
templateTemplate content to render.
raw_bodyfalseWhen false, parse the captured body as JSON before templating. When true, expose raw bytes.
status_codecaptured statusOverride the response status.
valueLoaded data key expected to be a map. Exposed as .value.
additionalExtra values exposed as .additional.
headersResponse headers applied when the template is used.
apply_status_codesallRender only for selected captured response statuses.
trustfalseEnable powerful template functions.
work_dirWorking directory for template functions that need one.
delims[', ']Two custom template delimiters.

Template data includes body, body_raw, method, headers, query_params, cookies, path, value, and additional.