gohugoio/hugo · error
want 1 or 2 arguments
Error message
want 1 or 2 arguments
What it means
Argument-count validation at the top of cachedContentScope.RenderString in page__content.go. The template method `.RenderString` accepts either just the string to render, or an options map plus the string; any other arity (zero args, or three or more) returns this error before any rendering happens.
Source
Thrown at hugolib/page__content.go:882
ctx = c.prepareContext(ctx)
cr, err := c.contentRendered(ctx)
if err != nil {
return "", err
}
return cr.contentWithoutSummary, nil
}
func (c *cachedContentScope) Summary(ctx context.Context) (page.Summary, error) {
ctx = c.prepareContext(ctx)
rendered, err := c.contentRendered(ctx)
return rendered.summary, err
}
func (c *cachedContentScope) RenderString(ctx context.Context, args ...any) (template.HTML, error) {
ctx = c.prepareContext(ctx)
if len(args) < 1 || len(args) > 2 {
return "", errors.New("want 1 or 2 arguments")
}
pco := c.pco
var contentToRender string
opts := defaultRenderStringOpts
sidx := 1
if len(args) == 1 {
sidx = 0
} else {
m, ok := args[0].(map[string]any)
if !ok {
return "", errors.New("first argument must be a map")
}
if err := mapstructure.WeakDecode(m, &opts); err != nil {
return "", fmt.Errorf("failed to decode options: %w", err)View on GitHub ↗ (pinned to 8a468df065)
Solutions
- Call it as `{{ .RenderString $content }}` or `{{ .RenderString (dict "display" "inline") $content }}` — exactly one or two arguments.
- If using a pipeline, remember the piped value is appended as the last argument: `{{ $content | .RenderString $opts }}` is valid; don't also pass the content positionally.
- Ensure the options map is the FIRST argument and the string last.
Example fix
{{/* before */}}
{{ .RenderString }}
{{/* after */}}
{{ .RenderString .Params.subtitle }} Defensive patterns
Strategy: validation
Validate before calling
{{/* RenderString takes ([options,] content) — 1 or 2 args */}}
{{ $s := .RenderString "**md**" }}
{{ $s2 := .RenderString (dict "display" "inline") "**md**" }} Prevention
- Call .RenderString with exactly one content arg, optionally preceded by an options dict
- Pass options as a single dict, not separate key/value args
- Lint templates with a full test build in CI
When it happens
Trigger: Calling `$page.RenderString` from a template with no arguments or with 3+ arguments, e.g. `{{ .RenderString }}`, `{{ .RenderString $opts $s $extra }}`, or piping incorrectly so extra values become arguments.
Common situations: Forgetting the content argument when only passing an options dict; misusing pipelines like `{{ $a | .RenderString $b $c }}` (the piped value becomes a third argument); copying snippets that splat a slice of args; confusing RenderString with markdownify.
Related errors
- need at least 2 arguments to append
- must provide a Resource and optionally an options map
- operator argument must be string type
- can't evaluate the array by no match argument or more than o
- invalid arguments supplied to `time`
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/c515da0891620837.json.
Report an issue: GitHub ↗.