{"record":{"id":"01173f4c2853db4a","repo":"gohugoio/hugo","slug":"invalid-page-received-in-relref","errorCode":null,"errorMessage":"invalid Page received in RelRef","messagePattern":"invalid Page received in RelRef","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/urls/urls.go","lineNumber":110,"sourceCode":"// Ref returns the absolute URL path to a given content item from Page p.\nfunc (ns *Namespace) Ref(p any, args any) (string, error) {\n\tpp, ok := p.(urls.RefLinker)\n\tif !ok {\n\t\treturn \"\", errors.New(\"invalid Page received in Ref\")\n\t}\n\targsm, err := ns.refArgsToMap(args)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\ts, err := pp.Ref(argsm)\n\treturn s, err\n}\n\n// RelRef returns the relative URL path to a given content item from Page p.\nfunc (ns *Namespace) RelRef(p any, args any) (string, error) {\n\tpp, ok := p.(urls.RefLinker)\n\tif !ok {\n\t\treturn \"\", errors.New(\"invalid Page received in RelRef\")\n\t}\n\targsm, err := ns.refArgsToMap(args)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\ts, err := pp.RelRef(argsm)\n\treturn s, err\n}\n\nfunc (ns *Namespace) refArgsToMap(args any) (map[string]any, error) {\n\tvar (\n\t\ts  string\n\t\tof string\n\t)\n\n\tv := args\n\tif _, ok := v.([]any); ok {","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/urls/urls.go#L92-L128","documentation":"The urls.RelRef template function type-asserts its first argument to urls.RefLinker (urls.go:108-110), identical in structure to Ref. Only Hugo Page objects satisfy this interface. A non-Page first argument causes the assertion to fail and this error to be returned.","triggerScenarios":"Calling {{ relref .NonPageValue \"path\" }} where the first argument is nil, a string, .Site, .Params, or any non-Page object.","commonSituations":"Same as Ref: partials without page context, passing the wrong dot value, calling relref on resources or term objects.","solutions":["Ensure the first argument is a Page object (use . in page scope or an explicitly captured $page)","Pass the page explicitly into partials that use relref","Confirm the template executes in page context"],"exampleFix":"{{/* before */}}\n{{ relref . \"posts/my-post\" }}\n{{/* after */}}\n{{ relref $page \"posts/my-post\" }}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// Check the value satisfies urls.RefLinker before calling relref.\nfunc isRefLinker(v any) bool {\n    _, ok := v.(urls.RefLinker)\n    return ok\n}","tryCatchPattern":"{{ if partial \"is-page.html\" . }}{{ relref . \"path\" }}{{ else }}{{ warnf \"relref: not a page\" }}{{ end }}","preventionTips":["Always call ref/relref in page context","Pass the page object explicitly into partials","Test templates that use relref in non-page contexts (RSS, sitemap) by passing a page explicitly"],"tags":["urls","relref","template","page","type-assertion","hugo"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}