{"id":"5bc6c49779c708f0","repo":"gohugoio/hugo","slug":"s-isn-t-a-field-of-struct-type-s","errorCode":null,"errorMessage":"%s isn't a field of struct type %s","messagePattern":"(.+?) isn't a field of struct type (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/collections/where.go","lineNumber":376,"sourceCode":"\t}\n\n\t// elemName isn't a method so next start to check whether it is\n\t// a struct field or a map value. In both cases, it mustn't be\n\t// a nil value\n\tif isNil {\n\t\treturn zero, fmt.Errorf(\"can't evaluate a nil pointer of type %s by a struct field or map key name %s\", typ, elemName)\n\t}\n\tobj = reflect.Indirect(obj)\n\tswitch obj.Kind() {\n\tcase reflect.Struct:\n\t\tft, ok := obj.Type().FieldByName(elemName)\n\t\tif ok {\n\t\t\tif ft.PkgPath != \"\" && !ft.Anonymous {\n\t\t\t\treturn zero, fmt.Errorf(\"%s is an unexported field of struct type %s\", elemName, typ)\n\t\t\t}\n\t\t\treturn obj.FieldByIndex(ft.Index), nil\n\t\t}\n\t\treturn zero, fmt.Errorf(\"%s isn't a field of struct type %s\", elemName, typ)\n\tcase reflect.Map:\n\t\tkv := reflect.ValueOf(elemName)\n\t\tif kv.Type().AssignableTo(obj.Type().Key()) {\n\t\t\treturn obj.MapIndex(kv), nil\n\t\t}\n\t\treturn zero, fmt.Errorf(\"%s isn't a key of map type %s\", elemName, typ)\n\t}\n\treturn zero, fmt.Errorf(\"%s is neither a struct field, a method nor a map element of type %s\", elemName, typ)\n}\n\n// parseWhereArgs parses the end arguments to the where function.  Return a\n// match value and an operator, if one is defined.\nfunc parseWhereArgs(args ...any) (mv reflect.Value, op string, err error) {\n\tswitch len(args) {\n\tcase 1:\n\t\tmv = reflect.ValueOf(args[0])\n\tcase 2:\n\t\tvar ok bool","sourceCodeStart":358,"sourceCodeEnd":394,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/tpl/collections/where.go#L358-L394","documentation":"The element being filtered is a struct, and after failing to find a matching method, reflect's FieldByName found no field with the given name. Hugo reports the exact struct type so the author can see what they were actually filtering, since `where` requires the key to resolve on every element it inspects.","triggerScenarios":"`where` over a slice of structs (e.g. Pages) with a key that is neither a field nor method of that struct: `where .Site.RegularPages \"Sction\" \"blog\"` (typo), or using a Params key directly without the `Params.` prefix on a struct-typed element.","commonSituations":"Typos in field names; expecting front-matter params to be top-level fields (`where .Pages \"author\" x` instead of `\"Params.author\"`); Hugo version upgrades that renamed or removed struct fields.","solutions":["Fix the field name spelling/casing to match an exported field or method.","For front-matter values, prefix with `Params.`, e.g. `where .Site.RegularPages \"Params.author\" \"jane\"`.","Print one element's structure with `{{ printf \"%#v\" (index $c 0) }}` or `jsonify` to see available fields."],"exampleFix":"<!-- before -->\n{{ range where .Site.RegularPages \"author\" \"jane\" }}\n<!-- after -->\n{{ range where .Site.RegularPages \"Params.author\" \"jane\" }}","handlingStrategy":"validation","validationCode":"{{ $first := index $pages 0 }}\n{{ if isset $first \"Draft\" }}{{ $r = where $pages \"Draft\" false }}{{ end }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify the field name exists on the element type (case-sensitive, exported) before using it in where","Use printf \"%#v\" on one element during development to inspect available fields","Prefer documented Page fields/methods over guessed names"],"tags":["hugo","templates","where","struct","front-matter"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}