# Is there a way to render the {{\< relref .. \>}} shortcode in Page front-matter variables

**URL:** <https://discourse.gohugo.io/t/is-there-a-way-to-render-the-relref-shortcode-in-page-front-matter-variables/38596>\
**Category:** support\
**Created:** [May 12, 2022, 2:42pm UTC](https://discourse.gohugo.io/t/is-there-a-way-to-render-the-relref-shortcode-in-page-front-matter-variables/38596 "2022-05-12T14:42:22Z")\
**Posts on this page:** 13\
**Page:** 1

<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:** [May 12, 2022, 2:42pm UTC](https://discourse.gohugo.io/t/is-there-a-way-to-render-the-relref-shortcode-in-page-front-matter-variables/38596/1 "2022-05-12T14:42:22Z")

</div>

Hello,

I am aware that `markdownify` or `$.Page.RenderString` cannot render the `{{< relref .. >}}` shortcodes in strings. But I want to check if anyone has figured out a workaround or something to do that.

In my post writing flow, I add post updates to a front-matter array-type variable and that can contain relrefs referring to other posts on the same website. It would be cool if those relrefs can be rendered by Hugo. _For now, I am using hard-coded URLs instead of relrefs when referring to other posts in those front-matter variables._

### Intended example use

```toml
+++
title = "my post"
[logbook]
  [logbook._toplevel]
    [[logbook._toplevel.notes]]
      timestamp = 2022-04-15T00:00:00-04:00
      note = """
  This post was re-exported today to get better `info:` link exports as
  described in [a newer post]({{< relref "that-other-post" >}}).
  """

```

---

<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:** [May 12, 2022, 6:36pm UTC](https://discourse.gohugo.io/t/is-there-a-way-to-render-the-relref-shortcode-in-page-front-matter-variables/38596/2 "2022-05-12T18:36:57Z")

</div>

So, the `relref` shortcode is one of the things I’m not … totally happy about in Hugo, which I kind of hoped would silently varnish like an old oak table once we got link render hooks … That sad, if you do:

```auto
+++
title = "my post"
[logbook]
  [logbook._toplevel]
    [[logbook._toplevel.notes]]
      timestamp = 2022-04-15T00:00:00-04:00
      note = """
  This post was re-exported today to get better `info:` link exports as
  described in [a newer post]({/that-other-post).
  """

```

And create a render hook that mimics what `relref` is doing (should not be too hard, there are plenty of examples floating around), and then use ` $.Page.RenderString` to render the `note`.

---

<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:** [May 12, 2022, 6:58pm UTC](https://discourse.gohugo.io/t/is-there-a-way-to-render-the-relref-shortcode-in-page-front-matter-variables/38596/3 "2022-05-12T18:58:19Z")

</div>

> [@bep](#):
>
> And create a render hook that mimics what `relref` is doing

OK, I see what you mean. This would mean a big change in the `ox-hugo` exporter I have been using. `relref` and `figure` are the only 2 shortcodes it depends on.

I personal appreciate the availability of `relref` because Hugo deals with the link validity and resolution under the hood.

I’ll add a long term goal to get rid of the `relref` shortcode in exports — the main problem is that all the `ox-hugo` users will need to add the special link render hook to their sites and themes.

* * *

Alternatively, can `$.Page.RenderString` be updated to treat the `relref` shortcode as a special element and resolve the link?

---

<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:** [May 12, 2022, 7:38pm UTC](https://discourse.gohugo.io/t/is-there-a-way-to-render-the-relref-shortcode-in-page-front-matter-variables/38596/4 "2022-05-12T19:38:39Z")

</div>

> [@kaushalmodi](#):
>
> Alternatively, can `$.Page.RenderString` be updated to treat the `relref` shortcode as a special element and resolve the link?

No, that’s not going to happen. `$.Page.RenderString` will eventually get shortcode support, though.

---

<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:** [May 12, 2022, 7:49pm UTC](https://discourse.gohugo.io/t/is-there-a-way-to-render-the-relref-shortcode-in-page-front-matter-variables/38596/5 "2022-05-12T19:49:47Z")

</div>

> [@bep](#):
>
> `$.Page.RenderString` will eventually get shortcode support, though.

Well, that will be great! I’ll wait for that, and also start planning on how to stop exporting relref’s.

One problem I see with the render hooks is that we will end up with clashes where a theme might be doing something special with those hooks whereas a user would need to add a hook just to mimick the relref behavior. I am unable to see the link render hook as a solution that will Just Work out of the box for all the users.

---

<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:** [May 12, 2022, 8:10pm UTC](https://discourse.gohugo.io/t/is-there-a-way-to-render-the-relref-shortcode-in-page-front-matter-variables/38596/6 "2022-05-12T20:10:32Z")

</div>

> [@kaushalmodi](#):
>
> One problem I see with the render hooks is that we will end up with clashes where a theme might be doing something special with those hooks whereas a user would need to add a hook just to mimick the relref behavior.

Yea, maybe, but in my head

- The main motivation behind render hooks was to make it possible to resolve resources (links, images) behind the scenes while preserving more or less the Markdown in its standard form (browsable on GitHub etc.)
- I understand that it’s tempting to use it to … add markup and shit, but …
- relref/ref is stil there, but I find it rather … intrusive.

---

<div class="post-metadata">

**Author:** ![Georg](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/georg/32/21486_2.png) [@Georg](https://discourse.gohugo.io/u/Georg)\
**Post date:** [May 13, 2022, 7:15pm UTC](https://discourse.gohugo.io/t/is-there-a-way-to-render-the-relref-shortcode-in-page-front-matter-variables/38596/7 "2022-05-13T19:15:41Z")

</div>

I’m using `relref` a lot because it’s convenient to check the links and get a relative path on a bigger site. But I do get your point. It’s annoying to always have to use a shortcode inside of Markdown. So I’m considering to include the functionality into my render-link hook.

In your example for GitHub-compatible links, you’re using .Page.GetPage to retrieve relative URLs.  
Is there a reason to prefer this method over the `relref` function?

---

<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:** [May 13, 2022, 7:18pm UTC](https://discourse.gohugo.io/t/is-there-a-way-to-render-the-relref-shortcode-in-page-front-matter-variables/38596/8 "2022-05-13T19:18:33Z")

</div>

> [@Georg](#):
>
> Is there a reason to prefer this method over the `relref` function?

I have mentioned the reason above: Portable links/markdown. Images/links that also works on GitHub etc.

That may not be important in many situations, but in common Hugo documentation sites hosted on GitHub, I think it’s a big deal.

---

<div class="post-metadata">

**Author:** ![Georg](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/georg/32/21486_2.png) [@Georg](https://discourse.gohugo.io/u/Georg)\
**Post date:** [May 13, 2022, 7:21pm UTC](https://discourse.gohugo.io/t/is-there-a-way-to-render-the-relref-shortcode-in-page-front-matter-variables/38596/9 "2022-05-13T19:21:48Z")

</div>

Yes, sorry, I didn’t make myself clear enough. I meant the `relref` function for templates. But probably it won’t work inside a hook, I suppose.

---

<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:** [May 13, 2022, 7:25pm UTC](https://discourse.gohugo.io/t/is-there-a-way-to-render-the-relref-shortcode-in-page-front-matter-variables/38596/10 "2022-05-13T19:25:39Z")

</div>

> [@Georg](#):
>
> In your example for GitHub-compatible links, you’re using .Page.GetPage to retrieve relative URLs.  
> Is there a reason to prefer this method over the `relref` function?

OK, now I get it. No, there is no reason for that. I guess I forgot that it was there …

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [May 15, 2022, 2:18pm UTC](https://discourse.gohugo.io/t/is-there-a-way-to-render-the-relref-shortcode-in-page-front-matter-variables/38596/11 "2022-05-15T14:18:42Z")

</div>

@Georg

The `ref` and `relref` functions emit a warning or error (configurable) when the path cannot be resolved to a page.

The `.GetPage` method gives you more control over what happens when a path cannot be resolved to a page.

---

<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:** [May 30, 2022, 9:49pm UTC](https://discourse.gohugo.io/t/is-there-a-way-to-render-the-relref-shortcode-in-page-front-matter-variables/38596/12 "2022-05-30T21:49:47Z")

</div>

Thanks for adding this support in [Make .RenderString render shortcodes · gohugoio/hugo@9e904d7 · GitHub](https://github.com/gohugoio/hugo/commit/9e904d756be02ca30e4cd9abb1eae8ba01f9c8af). I quickly tested out the master branch locally to see this feature work as expected.

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/gohugo/original/3X/e/0/e0555598c4de9365c4c6f77d08c49dc7adceed51.png)

([reference commit on my test site](https://gitlab.com/hugo-mwe/hugo-mwe/-/commit/762754e7e1c9ea88b114f6d8c05bbc3f1fdc804d))

* * *

For anyone following this thread, relref (or any other shortcode) will be rendered using page object’s `.RenderString` in [upcoming Hugo v0.100.0](https://github.com/gohugoio/hugo/issues/9934).

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [June 1, 2022, 9:50pm UTC](https://discourse.gohugo.io/t/is-there-a-way-to-render-the-relref-shortcode-in-page-front-matter-variables/38596/13 "2022-06-01T21:50:15Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
