gohugoio/hugo · error
{key} is neither a field nor a method of Page
Error message
{key} is neither a field nor a method of Page What it means
`GroupBy` first looks the key up as a method; if not found it tries the Page struct field via `FieldByName` (pagegroup.go:141-143). If neither matches, the key is genuinely unknown and grouping cannot proceed.
Source
Thrown at resources/page/pagegroup.go:143
var ft any
index := hreflect.GetMethodIndexByName(pagePtrType, key)
if index != -1 {
m := pagePtrType.Method(index)
if m.Type.NumOut() == 0 || m.Type.NumOut() > 2 {
return nil, errors.New(key + " is a Page method but you can't use it with GroupBy")
}
if m.Type.NumOut() == 1 && m.Type.Out(0).Implements(errorType) {
return nil, errors.New(key + " is a Page method but you can't use it with GroupBy")
}
if m.Type.NumOut() == 2 && !m.Type.Out(1).Implements(errorType) {
return nil, errors.New(key + " is a Page method but you can't use it with GroupBy")
}
ft = m
} else {
var ok bool
ft, ok = pagePtrType.Elem().FieldByName(key)
if !ok {
return nil, errors.New(key + " is neither a field nor a method of Page")
}
}
var tmp reflect.Value
switch e := ft.(type) {
case reflect.StructField:
tmp = reflect.MakeMap(reflect.MapOf(e.Type, pagesType))
case reflect.Method:
tmp = reflect.MakeMap(reflect.MapOf(e.Type.Out(0), pagesType))
}
for _, e := range p {
ppv := reflect.ValueOf(e)
var fv reflect.Value
switch ft.(type) {
case reflect.StructField:
fv = ppv.Elem().FieldByName(key)
case reflect.Method:View on GitHub (pinned to 52c9bd7908)
Solutions
- Verify the name is an exported Page field or method (see Hugo's Page object docs).
- For front-matter params, use `{{ .Pages.GroupByParam "myparam" }}` instead of GroupBy.
- Check spelling and capitalization.
Example fix
{{/* before: not a Page field/method */}}
{{ .Pages.GroupBy "myauthor" }}
{{/* after: group by a front matter param */}}
{{ .Pages.GroupByParam "myauthor" }} Defensive patterns
Strategy: validation
Prevention
- Use GroupByParam for front-matter params, GroupBy for Page fields/methods.
- Verify the name against Hugo's Page object reference.
When it happens
Trigger: Calling `{{ .Pages.GroupBy "Foo" }}` where `Foo` is neither an exported Page method nor an exported Page struct field — e.g. a typo, a param name, or a removed field.
Common situations: Typo in the field/method name; trying to group by a front-matter param (use GroupByParam instead); referencing a field removed in a Hugo version upgrade; case sensitivity mistakes.
Related errors
- {key} is a Page method but you can't use it with GroupBy
- can't apply the operator to the values
- quality ranges from 1 to 100 inclusive
- invalid image dimensions
- must provide Width and Height
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/e65faacdbf09fe79.
Report an issue: GitHub.