{"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/8a468df065a75c1c7cf9f6850f32148746590ea5/tpl/urls/urls.go#L92-L128","documentation":"Identical to the Ref case but for `relref`: the first argument must be a Page implementing the RefLinker interface so Hugo can resolve a relative URL from that page's position. A non-Page first argument (string, dict, nil) triggers this error immediately.","triggerScenarios":"`{{ relref \"about.md\" }}`-style calls missing the page argument, `{{ relref . \"x\" }}` inside a shortcode or partial where `.` is not a Page, or passing a params dict as the context.","commonSituations":"Shortcodes using `.` instead of `.Page`; partials called with a custom dict that loses the Page; templates ported from docs examples that assumed a page context; theme partials invoked from non-page contexts like 404 or taxonomy edge cases.","solutions":["Pass the Page explicitly: `{{ relref page \"about.md\" }}` or `{{ relref .Page \"about.md\" }}` in shortcodes.","When calling partials, thread the Page through the dict and use it as relref's first argument.","If you only need a link in content files, use the `relref` shortcode (`{{% raw %}}{{< relref \"about.md\" >}}{{% /raw %}}`), which supplies the page automatically."],"exampleFix":"{{/* before, in a partial with dict context */}}\n{{ relref . \"docs/setup.md\" }}\n{{/* after */}}\n{{ relref .page \"docs/setup.md\" }}{{/* where .page was passed in the dict */}}","handlingStrategy":"type-guard","validationCode":"{{ with .Page }}{{ relref . \"/blog/post\" }}{{ end }}","typeGuard":"{{/* ensure the dot is a Page before relref */}}\n{{ with $.Page }}{{ $url := relref . \"/docs/intro\" }}{{ end }}","tryCatchPattern":"{{ with try (relref $page \"/docs/intro\") }}\n  {{ with .Err }}{{ warnf \"relref failed: %s\" . }}{{ end }}\n{{ end }}","preventionTips":["Always give relref a real Page as its first argument — capture {{ $page := . }} at template top before entering range loops that rebind the dot","Pass .Page into partials that need to resolve links instead of relying on their local context","Use the built-in relref shortcode in Markdown content so the Page is supplied for you"],"tags":["hugo","templates","relref","page-context"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}