gohugoio/hugo · error
invalid Page received in RelRef
Error message
invalid Page received in RelRef
What it means
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.
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
Example fix
{{/* before */}}
{{ relref . "posts/my-post" }}
{{/* after */}}
{{ relref $page "posts/my-post" }} Defensive patterns
Strategy: type-guard
Type guard
// Check the value satisfies urls.RefLinker before calling relref.
func isRefLinker(v any) bool {
_, ok := v.(urls.RefLinker)
return ok
} Try / catch
{{ if partial "is-page.html" . }}{{ relref . "path" }}{{ else }}{{ warnf "relref: not a page" }}{{ end }} Prevention
- 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
When it happens
Trigger: Calling {{ relref .NonPageValue "path" }} where the first argument is nil, a string, .Site, .Params, or any non-Page object.
Common situations: Same as Ref: partials without page context, passing the wrong dot value, calling relref on resources or term objects.
Related errors
- invalid Page received in Ref
- invalid number of arguments to ref
- argument must be a slice
- arguments must be slices or arrays
- arguments to complement must be slices or arrays
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/01173f4c2853db4a.
Report an issue: GitHub.
Appendix: source
Thrown at tpl/urls/urls.go:110
// Ref returns the absolute URL path to a given content item from Page p.
func (ns *Namespace) Ref(p any, args any) (string, error) {
pp, ok := p.(urls.RefLinker)
if !ok {
return "", errors.New("invalid Page received in Ref")
}
argsm, err := ns.refArgsToMap(args)
if err != nil {
return "", err
}
s, err := pp.Ref(argsm)
return s, err
}
// RelRef returns the relative URL path to a given content item from Page p.
func (ns *Namespace) RelRef(p any, args any) (string, error) {
pp, ok := p.(urls.RefLinker)
if !ok {
return "", errors.New("invalid Page received in RelRef")
}
argsm, err := ns.refArgsToMap(args)
if err != nil {
return "", err
}
s, err := pp.RelRef(argsm)
return s, err
}
func (ns *Namespace) refArgsToMap(args any) (map[string]any, error) {
var (
s string
of string
)
v := args
if _, ok := v.([]any); ok {View on GitHub (pinned to 52c9bd7908)