gohugoio/hugo · error

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.

Solutions

  1. Verify the name is an exported Page field or method (see Hugo's Page object docs).
  2. For front-matter params, use `{{ .Pages.GroupByParam "myparam" }}` instead of GroupBy.
  3. 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

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


AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09). Data as JSON: /api/errors/e65faacdbf09fe79. Report an issue: GitHub.

Appendix: 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)