{"record":{"id":"d9234c31db29c237","repo":"kataras/iris","slug":"please-provide-a-map-string-any-type-as-the-bindin","errorCode":null,"errorMessage":"please provide a map[string]any type as the binding instead of the %#v","messagePattern":"please provide a map\\[string\\]any type as the binding instead of the %#v","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"view/handlebars.go","lineNumber":238,"sourceCode":"\t}\n\n\tisLayout := false\n\tlayout = getLayout(layout, s.layout)\n\trenderFilename := filename\n\n\tif layout != \"\" {\n\t\tisLayout = true\n\t\trenderFilename = layout // the render becomes the layout, and the name is the partial.\n\t}\n\n\tif tmpl := s.fromCache(renderFilename); tmpl != nil {\n\t\tbinding := bindingData\n\t\tif isLayout {\n\t\t\tvar context map[string]any\n\t\t\tif m, is := binding.(map[string]any); is { // handlebars accepts maps,\n\t\t\t\tcontext = m\n\t\t\t} else {\n\t\t\t\treturn fmt.Errorf(\"please provide a map[string]any type as the binding instead of the %#v\", binding)\n\t\t\t}\n\n\t\t\tcontents, err := s.executeTemplateBuf(filename, binding)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tif context == nil {\n\t\t\t\tcontext = make(map[string]any, 1)\n\t\t\t}\n\t\t\t// I'm implemented the {{ yield . }} as with the rest of template engines, so this is not inneed for iris, but the user can do that manually if want\n\t\t\t// there is no performance cost: raymond.RegisterPartialTemplate(name, tmpl)\n\t\t\tcontext[\"yield\"] = raymond.SafeString(contents)\n\t\t}\n\n\t\tres, err := tmpl.Exec(binding)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/view/handlebars.go#L220-L256","documentation":"The Handlebars engine requires the view binding data to be a map[string]any when rendering with a layout, because it injects the rendered partial into the layout context via a \"yield\" key on that map. If ExecuteWriter is called with a layout and any other binding type (struct, pointer, slice, nil non-map), the engine cannot attach the yield value and returns this error instead of rendering.","triggerScenarios":"Calling HTMLEngine/Handlebars ExecuteWriter(w, filename, layout, binding) where layout is non-empty (or a global layout is configured) and binding is not a map[string]any — e.g. a struct, *struct, map[string]string, or any custom type.","commonSituations":"Developers render with a layout while passing a typed view-model struct that works fine without layouts; or after migrating from another engine (html/template accepts structs) to handlebars; or passing map[string]string which is not map[string]any.","solutions":["Convert the binding to map[string]any before calling ExecuteWriter when a layout is used.","Render without a layout (pass view.NoLayout as the layout argument) if a struct binding is required.","Marshal the struct to a map via a helper (e.g. json round-trip or a ToMap function) so any struct can still be used."],"exampleFix":"// before\nerr := view.ExecuteWriter(w, \"index\", \"layouts/main\", myStruct)\n// after\nbinding := map[string]any{\"Title\": myStruct.Title, \"Items\": myStruct.Items}\nerr := view.ExecuteWriter(w, \"index\", \"layouts/main\", binding)","handlingStrategy":"type-guard","validationCode":"if _, ok := binding.(map[string]any); !ok && layout != \"\" {\n    return fmt.Errorf(\"handlebars layout rendering requires map[string]any binding, got %T\", binding)\n}","typeGuard":"func isMapBinding(v any) (map[string]any, bool) {\n    m, ok := v.(map[string]any)\n    return m, ok\n}","tryCatchPattern":"if err := v.ExecuteWriter(w, \"index.html\", \"layouts/main.html\", binding); err != nil {\n    var bindErr *fmt.wrapError // inspect for type-mismatch message\n    log.Printf(\"render failed: %v\", err)\n    http.Error(w, \"template error\", http.StatusInternalServerError)\n}","preventionTips":["Always build view-models as map[string]any when the engine is handlebars and layouts are in use.","Write a helper that converts structs to map[string]any once and reuse it for every render call.","Add a startup smoke-render test that renders each template with its layout using production-shaped data."],"tags":["handlebars","view-engine","type-mismatch","layout"],"backgroundTag":"invalid-binding-type","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}