gohugoio/hugo · error
too many arguments, expected 0 or 1
Error message
too many arguments, expected 0 or 1
What it means
Panic in pageContentOutput.Markup: the variadic opts slice has length > 1. The Markup method accepts zero or one argument (an optional scope string selecting a content scope); passing two or more is a usage error by the template/Go author calling it.
Source
Thrown at hugolib/page__per_output.go:138
// Make sure to send the *pageState and not the *pageContentOutput to the template.
res, err := executeToString(ctx, pco.po.p.s.GetTemplateStore(), templ, pco.po.p)
if err != nil {
return "", pco.po.p.wrapError(fmt.Errorf("failed to execute template %s: %w", templ.Name(), err))
}
return template.HTML(res), nil
}
func (pco *pageContentOutput) Fragments(ctx context.Context) *tableofcontents.Fragments {
return pco.c().Fragments(ctx)
}
func (pco *pageContentOutput) RenderShortcodes(ctx context.Context) (template.HTML, error) {
return pco.c().RenderShortcodes(ctx)
}
func (pco *pageContentOutput) Markup(opts ...any) page.Markup {
if len(opts) > 1 {
panic("too many arguments, expected 0 or 1")
}
var scope string
if len(opts) == 1 {
scope = cast.ToString(opts[0])
}
return pco.po.p.m.content.getOrCreateScope(scope, pco)
}
func (pco *pageContentOutput) c() page.Markup {
return pco.po.p.m.content.getOrCreateScope("", pco)
}
func (pco *pageContentOutput) Content(ctx context.Context) (any, error) {
r, err := pco.c().Render(ctx)
if err != nil {
return nil, err
}
return r.Content(ctx)View on GitHub (pinned to 52c9bd7908)
Solutions
- Call Markup with at most one argument: {{ .Markup }} or {{ .Markup "scope" }}.
- If you need to pass multiple values, bundle them into a single scope string.
- Check the template/Go call site reported in the stack trace and remove the extra argument.
Example fix
{{/* before */}}
{{ .Markup "main" "extra" }}
{{/* after */}}
{{ .Markup "main" }} Defensive patterns
Strategy: validation
Validate before calling
// Call Markup with 0 or 1 argument only.
// Template: {{ .Markup }} or {{ .Markup "scope" }}
// Go: pco.Markup() pco.Markup("scope")
// If a variable number is unavoidable, slice to the first element before calling. Type guard
// Limit opts before calling Markup.
func safeMarkup(p MarkupProvider, opts ...any) page.Markup {
if len(opts) > 1 {
opts = opts[:1]
}
return p.Markup(opts...)
} Prevention
- Pass at most one argument to Markup.
- Bundle multiple values into a single scope string.
- Inspect template call sites after copy-paste.
- Add a template lint rule for Markup arity.
When it happens
Trigger: Calling .Markup(a, b) or {{ .Markup "x" "y" }} from a template, or invoking pageContentOutput.Markup with multiple arguments via Go. The method signature is Markup(opts ...any) page.Markup but only 0 or 1 opt is valid.
Common situations: A template author calls Markup with extra arguments by mistake. Passing a slice where individual args are expected. Copy-paste from a different API. A render hook invoking Markup incorrectly.
Related errors
- ContentMediaType not set
- unknown dimension %q
- alignx must be one of left, center, right
- error building site: %w
- failed to render shortcode: %w
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/baefac242faac9ab.
Report an issue: GitHub.