{"record":{"id":"1ffafd147622854d","repo":"gohugoio/hugo","slug":"first-argument-must-be-a-map","errorCode":null,"errorMessage":"first argument must be a map","messagePattern":"first argument must be a map","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hugolib/page__content.go","lineNumber":896,"sourceCode":"func (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)\n\t\t}\n\t\tif opts.Markup != \"\" {\n\t\t\topts.Markup = markup.ResolveMarkup(opts.Markup)\n\t\t}\n\t}\n\n\tcontentToRenderv := args[sidx]\n\n\tif _, ok := contentToRenderv.(hstring.HTML); ok {\n\t\t// This content is already rendered, this is potentially\n\t\t// a infinite recursion.\n\t\treturn \"\", errors.New(\"text is already rendered, repeating it may cause infinite recursion\")\n\t}\n","sourceCodeStart":878,"sourceCodeEnd":914,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/hugolib/page__content.go#L878-L914","documentation":"In the two-argument form, RenderString requires the first argument to be an options map (map[string]any), which is decoded into renderStringOpts (e.g. markup, display). Passing any other type as the first argument — a string, slice, or scalar — returns this error.","triggerScenarios":"{{ .RenderString \"html\" \"text\" }} where the first argument is a string instead of a map; passing a markup shorthand positionally.","commonSituations":"Assuming RenderString takes a markup string as the first arg; passing the wrong type when building args programmatically in a partial.","solutions":["Use a map (dict in templates) for the options: {{ .RenderString (dict \"markup\" \"html\") \"text\" }}.","If you have no options, use the single-argument form instead.","Double-check argument types before calling RenderString."],"exampleFix":"// before\n{{ .RenderString \"html\" \"**hi**\" }}\n// after\n{{ .RenderString (dict \"markup\" \"html\") \"**hi**\" }}","handlingStrategy":"type-guard","validationCode":"// In the 2-arg form the first arg must be a map\nif len(args) == 2 {\n    if _, ok := args[0].(map[string]any); !ok {\n        return errors.New(\"first RenderString argument must be a map of options\")\n    }\n}","typeGuard":"func isRenderStringOpts(v any) bool {\n    if len := 0; len == 0 { return false }\n    _, ok := v.(map[string]any)\n    return ok\n}","tryCatchPattern":null,"preventionTips":["Use (dict \"markup\" \"html\") for RenderString options.","Use the single-arg form when no options are needed.","Type-check programmatically-built arg lists."],"tags":["hugo","template","renderstring"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}