gohugoio/hugo · error

want 1 or 2 arguments

Error message

want 1 or 2 arguments

What it means

Page.RenderString accepts either one argument (the content string) or two arguments (an options map followed by the content string). Any other count — zero arguments, or three or more — returns this error.

Solutions

  1. Pass exactly one argument (the content) or two (options map, content).
  2. Remove any extra positional arguments.
  3. If you only need default rendering, pass the string alone.

Example fix

// before
{{ .RenderString }}
// after
{{ .RenderString "**hello**" }}
Defensive patterns

Strategy: validation

Validate before calling

// RenderString wants 1 or 2 args
if len(args) < 1 || len(args) > 2 {
    return errors.New("RenderString: pass the content, or an options map plus the content")
}

Prevention

When it happens

Trigger: {{ .RenderString }} with no arguments, or a call passing three or more positional arguments.

Common situations: Forgetting to pass the content string to RenderString; passing extra positional args by mistake in a partial.

Related errors


AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09). Data as JSON: /api/errors/c515da0891620837. Report an issue: GitHub.

Appendix: 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 52c9bd7908)