Ref and relref do not work if it is in layout folder


#1

if you use the following code:

{{ relref "content/post/post1.md" }}

or

{{ relref "post/post1.md" }}

hugo throws the following error

executing "partials/_left-menu.html" at <relref "content/post...>: error calling relref: invalid Page received in RelRef

I have the following folder structure:

- project
-- content
--- about
--- post
-- layouts
--- partials

#2

Based on the error you probably missed out passing the context (the dot) to the partial.

You need to show the full code (the site git repo) to get more help.


#3

@kaushalmodi thank you for the answer. I don’t know what the dot did mean, but if I remove rel/relref from html file then everything works well. The repo is here.


#4

You need to add the page to the call to relref (i.e. the dot). I think it is the first argument:

{{ relref . “content/post/post1.md” }}


#5

I meant a probable missing dot as the argument to the parent partial _left-menu.html.

Does relref function take two arguments? It’s documented to accept just one.


#6

In single.html, try changing:

{{ partial "_left-menu.html" }}

to:

{{ partial "_left-menu.html" . }}

That’s the dot I meant… search for “common mistakes” here :slight_smile:.


#7

Hi there, I’m having the same issue, but the dot seems to not work.
According to the documentation (https://gohugo.io/content-management/cross-references/) I deduced that I had to use:

<a href="{{ ref "mypost.markdown" }}" target="_new">UK y Gales SPTA</a>

or:

<a href="{{< ref "mypost.markdown" >}}" target="_new">UK y Gales SPTA</a>

None of then are working. Following this thread, I understood that I should use instead:

<a href="{{ ref "mypost.markdown" . }}" target="_new">UK y Gales SPTA</a>

but still not working.

Just in case it’s useful, here is my hugo version:
Hugo Static Site Generator v0.30.2 linux/amd64 BuildDate: 2017-10-19T13:34:27+02:00

It’s probably something silly, but I just don’t get it. Could you give any hint? Thanks for your time!


#8

It’s difficult to give any hint without looking at the site source.

  1. You need to link your site repo
  2. Explain what one should do after cloning that repo to see the problem.

#9

Hi! Thanks for your response:

  1. link to the repository: https://github.com/yamila-moreno/dendarii

  2. In the left sidebar there is a “CV viajero” section, inside you can see a map and a list. In this list, there are some links with “ref” (for instance “UK y Gales SPTA” at the top of the list). It should open the post with this name; instead, the “href” it’s badly rendered/processed with: “http://localhost:1313/cv-viajero {{”

Best,


#10

Thank you for the answer. I get the same error.


#11

Thank you guys, now it works. I had to apply @kaushalmodi solution with @bep solution. So:

// when calling partial template **the dot**
{{ partial "_left-menu.html" . }}

then

// then put the dot
{{ relref . "post/post1.md" }}

but it does not work with

{{ ref . "about/_index.md" }}

I guess it is documentation issue.


#12

Is there any way to bind to _index.md?
I was expected:

{{ ref . "about/_index.md" }} // "/about"

get the following error:

ERROR 2017/11/17 16:26:33 Error while rendering "home": template: index.html:5:15: 
executing "index.html" at <partial "_left-menu....>: 
error calling partial: template: partials/_left-menu.html:35:7: executing "partials/_left-menu.html" at <ref . "about/_index....>: 
error calling ref: No page found with path or logical name "about/_index.md".

#13

Same problem. Every ref or relref fails without any meaningful error. Tried everything above at random. The documentation is non-existant.