[Error] Using ref function in partial file

Hello there, going mad about using ref function lately.

All my files are placed in themes > “mytheme” folder.

in layouts \ _default \ baseof.html

<!DOCTYPE html>
<html lang="{{ $.Site.LanguageCode | default "fr" }}">
    {{- partial "head.html" . -}}
        {{- block "search" . }}{{- end }}
        <main {{ if isset .Params "class" }}class="{{.Params.class}}"{{ end }}>
        {{- block "main" . }}{{- end }}
        {{- block "filter" . }}{{- end }}
        {{- block "navigation" . }}{{- end }}
    {{- partial "script.html" . -}}

in layouts \ user \ hp.thml: I define my partial like this

{{ define "navigation" }}
    {{- partial "navigation.html" . -}}
{{ end }}

At least in layouts \ partials \ navigation.html: I tried to call
{{ ref . "/user/store" }}

I keep getting error : executing “partials/navigation.html” at <ref . “/user/store”>: error calling ref: invalid Page received in Ref

Why that ? I passed , why is it workin in a defin block but not in a partial file ?
How can I generate link (navigation) to pages ?

NB : I use block and partial to allow not having navigation or search depending on the page (that is why I’m not calling partial directly in the baseof file)

Thanks !

This is probably a problem with context (the value of the “dot” in your ref statement). Perhaps you’ve wrapped your ref statement in a range or with construct.

Feel free to post a link to the public repository for your project if you would like someone to take a closer look.

Thanks for replying so fast.

If I print [the dot] in the define “navigation” and in the partial “navigation.html” they have the same value.
Ref is working in the define block, but errors in the partial file.

Got a public copy of the template repo, you can find it here : GitHub - Frackher/magicKoala: A theme for hugo

The navigation partial doesn’t match what you posted.

1 Like

My dearest apologies, I’ve deleted it to pursue coding.
I’ve updated the project, now it’s good :slight_smile:

I cannot reproduce the problem with just the theme. I tried:

hugo new site mysite
cd mysite/
git init
git submodule add themes/magicKoala
echo 'theme = "magicKoala"' >> config.toml
hugo new user/
hugo new user/


title: "Foo"
date: 2021-07-29T11:02:43-07:00
draft: true
layout: hp

Then I ran hugo -D.

Please provide an entire site, complete with content.