{"id":"c515da0891620837","repo":"gohugoio/hugo","slug":"want-1-or-2-arguments","errorCode":null,"errorMessage":"want 1 or 2 arguments","messagePattern":"want 1 or 2 arguments","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hugolib/page__content.go","lineNumber":882,"sourceCode":"\tctx = c.prepareContext(ctx)\n\tcr, err := c.contentRendered(ctx)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\treturn cr.contentWithoutSummary, nil\n}\n\nfunc (c *cachedContentScope) Summary(ctx context.Context) (page.Summary, error) {\n\tctx = c.prepareContext(ctx)\n\trendered, err := c.contentRendered(ctx)\n\treturn rendered.summary, err\n}\n\nfunc (c *cachedContentScope) RenderString(ctx context.Context, args ...any) (template.HTML, error) {\n\tctx = c.prepareContext(ctx)\n\n\tif len(args) < 1 || len(args) > 2 {\n\t\treturn \"\", errors.New(\"want 1 or 2 arguments\")\n\t}\n\n\tpco := c.pco\n\n\tvar contentToRender string\n\topts := defaultRenderStringOpts\n\tsidx := 1\n\n\tif len(args) == 1 {\n\t\tsidx = 0\n\t} else {\n\t\tm, ok := args[0].(map[string]any)\n\t\tif !ok {\n\t\t\treturn \"\", errors.New(\"first argument must be a map\")\n\t\t}\n\n\t\tif err := mapstructure.WeakDecode(m, &opts); err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"failed to decode options: %w\", err)","sourceCodeStart":864,"sourceCodeEnd":900,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/hugolib/page__content.go#L864-L900","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"{{/* before */}}\n{{ .RenderString }}\n{{/* after */}}\n{{ .RenderString .Params.subtitle }}","handlingStrategy":"validation","validationCode":"{{/* RenderString takes ([options,] content) — 1 or 2 args */}}\n{{ $s := .RenderString \"**md**\" }}\n{{ $s2 := .RenderString (dict \"display\" \"inline\") \"**md**\" }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["hugo","templates","renderstring","arguments"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}