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

**URL:** <https://discourse.gohugo.io/t/ref-and-relref-do-not-work-if-it-is-in-layout-folder/9266>\
**Category:** Uncategorized\
**Created:** [November 17, 2017, 12:43pm UTC](https://discourse.gohugo.io/t/ref-and-relref-do-not-work-if-it-is-in-layout-folder/9266 "2017-11-17T12:43:57Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mirodil](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/mirodil/32/4596_2.png) [@Mirodil](https://discourse.gohugo.io/u/Mirodil)\
**Post date:** [November 17, 2017, 12:43pm UTC](https://discourse.gohugo.io/t/ref-and-relref-do-not-work-if-it-is-in-layout-folder/9266/1 "2017-11-17T12:43:57Z")

</div>

if you use the following code:

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

```

or

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

```

hugo throws the following error

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

```

I have the following folder structure:

```auto
- project
-- content
--- about
--- post
-- layouts
--- partials

```

---

<div class="post-metadata">

**Author:** ![kaushalmodi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/kaushalmodi/32/2567_2.png) [@kaushalmodi](https://discourse.gohugo.io/u/kaushalmodi)\
**Post date:** [November 17, 2017, 1:01pm UTC](https://discourse.gohugo.io/t/ref-and-relref-do-not-work-if-it-is-in-layout-folder/9266/2 "2017-11-17T13:01:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Mirodil](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/mirodil/32/4596_2.png) [@Mirodil](https://discourse.gohugo.io/u/Mirodil)\
**Post date:** [November 17, 2017, 1:48pm UTC](https://discourse.gohugo.io/t/ref-and-relref-do-not-work-if-it-is-in-layout-folder/9266/3 "2017-11-17T13:48:32Z")

</div>

@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](https://github.com/Mirodil/websnippet/tree/master).

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [November 17, 2017, 2:05pm UTC](https://discourse.gohugo.io/t/ref-and-relref-do-not-work-if-it-is-in-layout-folder/9266/4 "2017-11-17T14:05:48Z")

</div>

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” }}

---

<div class="post-metadata">

**Author:** ![kaushalmodi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/kaushalmodi/32/2567_2.png) [@kaushalmodi](https://discourse.gohugo.io/u/kaushalmodi)\
**Post date:** [November 17, 2017, 2:16pm UTC](https://discourse.gohugo.io/t/ref-and-relref-do-not-work-if-it-is-in-layout-folder/9266/5 "2017-11-17T14:16:46Z")

</div>

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](https://gohugo.io/functions/relref/) to accept just one.

---

<div class="post-metadata">

**Author:** ![kaushalmodi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/kaushalmodi/32/2567_2.png) [@kaushalmodi](https://discourse.gohugo.io/u/kaushalmodi)\
**Post date:** [November 17, 2017, 2:31pm UTC](https://discourse.gohugo.io/t/ref-and-relref-do-not-work-if-it-is-in-layout-folder/9266/6 "2017-11-17T14:31:36Z")

</div>

In [`single.html`](https://github.com/Mirodil/websnippet/blob/master/layouts/_default/single.html), try changing:

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

```

to:

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

```

That’s **the dot** I meant… search for “common mistakes” [here](https://gohugo.io/templates/partials/) 🙂.

---

<div class="post-metadata">

**Author:** ![yamila-moreno](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/yamila-moreno/32/3823_2.png) [@yamila-moreno](https://discourse.gohugo.io/u/yamila-moreno)\
**Post date:** [November 17, 2017, 7:11pm UTC](https://discourse.gohugo.io/t/ref-and-relref-do-not-work-if-it-is-in-layout-folder/9266/7 "2017-11-17T19:11:09Z")

</div>

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/](https://gohugo.io/content-management/cross-references/)) I deduced that I had to use:

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

```

or:

```auto
<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:

```auto
<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!

---

<div class="post-metadata">

**Author:** ![kaushalmodi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/kaushalmodi/32/2567_2.png) [@kaushalmodi](https://discourse.gohugo.io/u/kaushalmodi)\
**Post date:** [November 17, 2017, 8:35pm UTC](https://discourse.gohugo.io/t/ref-and-relref-do-not-work-if-it-is-in-layout-folder/9266/8 "2017-11-17T20:35:52Z")

</div>

> [@yamila-moreno](#):
>
> Could you give any hint?

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.

---

<div class="post-metadata">

**Author:** ![yamila-moreno](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/yamila-moreno/32/3823_2.png) [@yamila-moreno](https://discourse.gohugo.io/u/yamila-moreno)\
**Post date:** [November 17, 2017, 8:44pm UTC](https://discourse.gohugo.io/t/ref-and-relref-do-not-work-if-it-is-in-layout-folder/9266/9 "2017-11-17T20:44:01Z")

</div>

Hi! Thanks for your response:

1. link to the repository: [https://github.com/yamila-moreno/dendarii](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](http://localhost:1313/cv-viajero) {{”

Best,

---

<div class="post-metadata">

**Author:** ![Mirodil](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/mirodil/32/4596_2.png) [@Mirodil](https://discourse.gohugo.io/u/Mirodil)\
**Post date:** [November 17, 2017, 9:07pm UTC](https://discourse.gohugo.io/t/ref-and-relref-do-not-work-if-it-is-in-layout-folder/9266/10 "2017-11-17T21:07:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Mirodil](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/mirodil/32/4596_2.png) [@Mirodil](https://discourse.gohugo.io/u/Mirodil)\
**Post date:** [November 17, 2017, 9:19pm UTC](https://discourse.gohugo.io/t/ref-and-relref-do-not-work-if-it-is-in-layout-folder/9266/11 "2017-11-17T21:19:02Z")

</div>

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

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

```

then

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

```

but it does not work with

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

```

I guess it is documentation issue.

---

<div class="post-metadata">

**Author:** ![Mirodil](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/mirodil/32/4596_2.png) [@Mirodil](https://discourse.gohugo.io/u/Mirodil)\
**Post date:** [November 17, 2017, 9:25pm UTC](https://discourse.gohugo.io/t/ref-and-relref-do-not-work-if-it-is-in-layout-folder/9266/12 "2017-11-17T21:25:49Z")

</div>

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

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

```

get the following error:

```auto
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".

```

---

<div class="post-metadata">

**Author:** ![Marek\_Maurizio](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@Marek\_Maurizio](https://discourse.gohugo.io/u/Marek_Maurizio)\
**Post date:** [January 11, 2018, 10:17am UTC](https://discourse.gohugo.io/t/ref-and-relref-do-not-work-if-it-is-in-layout-folder/9266/13 "2018-01-11T10:17:30Z")

</div>

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