{"record":{"id":"7ca3394c86cb2fbc","repo":"gohugoio/hugo","slug":"invalid-page-received-in-ref","errorCode":null,"errorMessage":"invalid Page received in Ref","messagePattern":"invalid Page received in Ref","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/urls/urls.go","lineNumber":96,"sourceCode":"\t}\n\treturn ns.deps.PathSpec.URLize(ss), nil\n}\n\n// Anchorize creates sanitized anchor name version of the string s that is compatible\n// with how your configured markdown renderer does it.\nfunc (ns *Namespace) Anchorize(s any) (string, error) {\n\tss, err := cast.ToStringE(s)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\treturn ns.deps.ContentSpec.SanitizeAnchorName(ss), nil\n}\n\n// 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","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/urls/urls.go#L78-L114","documentation":"The urls.Ref template function type-asserts its first argument to urls.RefLinker (urls.go:94-96). Only Hugo Page objects satisfy this interface. When the value passed is not a Page (nil, string, .Site, .Params, a Resource, etc.), the assertion fails and this error is returned.","triggerScenarios":"Calling {{ ref .SomeNonPage \"path\" }} or {{ ref .Site \"path\" }} where the first argument does not implement urls.RefLinker.","commonSituations":"Using ref inside a partial whose dot context is not a Page; passing .Params or .Site instead of the page; calling ref on a resource or taxonomy term object.","solutions":["Ensure the first argument is a Page object (use . in page context or an explicitly passed $page)","If inside a partial, pass the page in: {{ partial \"myref.html\" (dict \"page\" .) }} and call {{ ref .page \"path\" }}","Verify the template is evaluated in page context and not in a root/site-only context"],"exampleFix":"{{/* before: . is not a Page here */}}\n{{ ref . \"posts/my-post\" }}\n{{/* after: pass the page explicitly */}}\n{{ ref $page \"posts/my-post\" }}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// In Go template code, check that the value is a Page before calling ref.\n{{ with reflect.IsMap . }}{{ end }}\n// In Go code:\nfunc isRefLinker(v any) bool {\n    _, ok := v.(urls.RefLinker)\n    return ok\n}","tryCatchPattern":"{{ if partial \"is-page.html\" . }}{{ ref . \"path\" }}{{ else }}{{ warnf \"ref: not a page\" }}{{ end }}","preventionTips":["Always call ref/relref in page context (dot is a Page)","Pass the page object explicitly into partials instead of relying on inherited context","Document which partials expect a Page in their dot context"],"tags":["urls","ref","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"}