gohugoio/hugo · error

%T cannot be merged by language

Error message

%T cannot be merged by language

What it means

Pages.MergeByLanguageInterface is the template-facing entry point for the `lang.Merge` template function. It accepts an untyped argument and requires it to be a page.Pages collection; any other type fails this type assertion and returns this error with the concrete Go type interpolated. It exists because templates pass `any` values that must be validated at runtime.

Source

Thrown at resources/page/pages_language_merge.go:60

		SortByDefault(*pages)
	}

	out, _ := spc.getP("pages.MergeByLanguage", merge, p1, p2)

	return out
}

// MergeByLanguageInterface is the generic version of MergeByLanguage. It
// is here just so it can be called from the tpl package.
// This is for internal use.
func (p1 Pages) MergeByLanguageInterface(in any) (any, error) {
	if in == nil {
		return p1, nil
	}
	p2, ok := in.(Pages)
	if !ok {
		return nil, fmt.Errorf("%T cannot be merged by language", in)
	}
	return p1.MergeByLanguage(p2), nil
}

View on GitHub ↗ (pinned to 8a468df065)

Solutions

  1. Ensure both arguments to `lang.Merge` are page collections, e.g. `{{ $merged := .Sites.First.RegularPages | lang.Merge .Site.RegularPages }}`.
  2. If you have a grouped or weighted result, convert it first (e.g. use `.Pages` on a PageGroup) before merging.
  3. Print the value's type with `{{ printf "%T" $x }}` to see what you're actually passing.

Example fix

// before
{{ $m := lang.Merge (.GetPage "/about") .Site.RegularPages }}
// after
{{ $m := lang.Merge .Sites.First.RegularPages .Site.RegularPages }}
Defensive patterns

Strategy: type-guard

Type guard

// Only page.Pages elements support language merging
func canMergeByLanguage(v any) bool {
    _, ok := v.(page.Page)
    return ok
}

Prevention

When it happens

Trigger: Calling `lang.Merge $a $b` (or Pages.MergeByLanguage via templates) where the second argument is not a Pages collection — e.g. a single Page, a slice from `slice`, a PageGroup, WeightedPages, or the result of a function that returned something else.

Common situations: Passing `.Site.RegularPages | first 5` results is fine, but passing a single page (`.GetPage ...`), a `where` result that got grouped, or `.Translations` of one page instead of a page collection; mixing up argument order with non-Pages values.

Related errors


AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31). Data as JSON: /data/errors/569201f5753931ae.json. Report an issue: GitHub ↗.