{"id":"569201f5753931ae","repo":"gohugoio/hugo","slug":"t-cannot-be-merged-by-language","errorCode":null,"errorMessage":"%T cannot be merged by language","messagePattern":"%T cannot be merged by language","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/page/pages_language_merge.go","lineNumber":60,"sourceCode":"\n\t\tSortByDefault(*pages)\n\t}\n\n\tout, _ := spc.getP(\"pages.MergeByLanguage\", merge, p1, p2)\n\n\treturn out\n}\n\n// MergeByLanguageInterface is the generic version of MergeByLanguage. It\n// is here just so it can be called from the tpl package.\n// This is for internal use.\nfunc (p1 Pages) MergeByLanguageInterface(in any) (any, error) {\n\tif in == nil {\n\t\treturn p1, nil\n\t}\n\tp2, ok := in.(Pages)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"%T cannot be merged by language\", in)\n\t}\n\treturn p1.MergeByLanguage(p2), nil\n}\n","sourceCodeStart":42,"sourceCodeEnd":64,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/resources/page/pages_language_merge.go#L42-L64","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure both arguments to `lang.Merge` are page collections, e.g. `{{ $merged := .Sites.First.RegularPages | lang.Merge .Site.RegularPages }}`.","If you have a grouped or weighted result, convert it first (e.g. use `.Pages` on a PageGroup) before merging.","Print the value's type with `{{ printf \"%T\" $x }}` to see what you're actually passing."],"exampleFix":"// before\n{{ $m := lang.Merge (.GetPage \"/about\") .Site.RegularPages }}\n// after\n{{ $m := lang.Merge .Sites.First.RegularPages .Site.RegularPages }}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// Only page.Pages elements support language merging\nfunc canMergeByLanguage(v any) bool {\n    _, ok := v.(page.Page)\n    return ok\n}","tryCatchPattern":null,"preventionTips":["Only pass Pages collections (not arbitrary slices/maps) to lang.Merge","Verify template pipelines feed .Pages or similar page collections into merge operations","Add an integration test rendering the multilingual template that exercises the merge"],"tags":["hugo","templates","multilingual","type-assertion"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}