# Render-Link Functionality Not Working

**URL:** <https://discourse.gohugo.io/t/render-link-functionality-not-working/26358>\
**Category:** support\
**Created:** [June 19, 2020, 12:22am UTC](https://discourse.gohugo.io/t/render-link-functionality-not-working/26358 "2020-06-19T00:22:27Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryan77](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/ryan77/32/11666_2.png) [@ryan77](https://discourse.gohugo.io/u/ryan77)\
**Post date:** [June 19, 2020, 12:22am UTC](https://discourse.gohugo.io/t/render-link-functionality-not-working/26358/1 "2020-06-19T00:22:28Z")

</div>

Hi all,

I have the following in my `layouts/_default/_markup/render-link.html` file:

```
{{ $url := .Destination | safeURL }}
{{ $findThis := "/redirect/" }}
{{ $hasIt := in $url $findThis }}
{{ $hasItPrefix := strings.HasPrefix $url $findThis }}
{{ $url }}<br />
{{ $hasIt }}<br />
{{ $hasItPrefix }}

```

This produces the following output on a page with an anchor link:

```
/redirect/external-site/
false
false

```

I would have expected `true` for both boolean lines, any ideas on what I’m missing?

I’m currently using Hugo v0.72.0.

Thank you for any help!

---

<div class="post-metadata">

**Author:** ![sciurius](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/sciurius/32/11499_2.png) [@sciurius](https://discourse.gohugo.io/u/sciurius)\
**Post date:** [June 19, 2020, 6:40am UTC](https://discourse.gohugo.io/t/render-link-functionality-not-working/26358/2 "2020-06-19T06:40:13Z")

</div>

I tried this as a partial (first line becomes

```auto
{{ $url := .Get 0 | safeURL }}

```

). The call

```auto
{{< xx "/redirect/external-site/" >}}

```

yields the url plus two times `true`.

Maybe your `.Destination` looks like a string but isn’t?

---

<div class="post-metadata">

**Author:** ![ryan77](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/ryan77/32/11666_2.png) [@ryan77](https://discourse.gohugo.io/u/ryan77)\
**Post date:** [June 19, 2020, 10:41am UTC](https://discourse.gohugo.io/t/render-link-functionality-not-working/26358/3 "2020-06-19T10:41:56Z")

</div>

Thank you for the suggestions.

When I change the first line to:

```
{{ $url := .Get 0 | safeURL }}

```

I get an error:

```
/layouts/_default/_markup/render-link.html:1:11": execute of template failed: template: 
_default/_markup/render-link.html:1:11: executing "_default/_markup/render-link.html" at <.Get>: can't evaluate field Get in type goldmark.linkCon /layouts/_default/_markup/render-link.html:1:11": execute of template failed: template: _default/_markup/render-link.html:1:11: 
executing "_default/_markup/render-link.html" at <.Get>: can't evaluate field Get in type goldmark.linkContext

/layouts/_default/_markup/render-link.html:1:11": 
execute of template failed: template: _default/_markup/render-link.html:1:11: 
executing "_default/_markup/render-link.html" at <.Get>: 
can't evaluate field Get in type goldmark.linkContext /layouts/_default/_markup/render-link.html:1:11": 
execute of template failed: template: _default/_markup/render-link.html:1:11: 
executing "_default/_markup/render-link.html" at <.Get>: can't evaluate field Get in type goldmark.linkContext

```

So it doesn’t appear to work, if I add the following type check to the bottom of my code I get `string` as the result:

```
{{ printf "%T" .Destination }}

```

If I do the following, it’s `template.URL`:

```
{{ printf "%T" (.Destination | safeURL) }}
```

---

<div class="post-metadata">

**Author:** ![sciurius](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/sciurius/32/11499_2.png) [@sciurius](https://discourse.gohugo.io/u/sciurius)\
**Post date:** [June 19, 2020, 11:26am UTC](https://discourse.gohugo.io/t/render-link-functionality-not-working/26358/4 "2020-06-19T11:26:54Z")

</div>

The change .Get 0 is when you use it as a shortcode.

---

<div class="post-metadata">

**Author:** ![ryan77](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/ryan77/32/11666_2.png) [@ryan77](https://discourse.gohugo.io/u/ryan77)\
**Post date:** [June 19, 2020, 11:55am UTC](https://discourse.gohugo.io/t/render-link-functionality-not-working/26358/5 "2020-06-19T11:55:13Z")

</div>

Ok, I’d like to try to get everything to work in the `render-link.html` file first. When I remove the `safeURL` from my first line in the original code it still produces the same result.

---

<div class="post-metadata">

**Author:** ![sciurius](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/sciurius/32/11499_2.png) [@sciurius](https://discourse.gohugo.io/u/sciurius)\
**Post date:** [June 19, 2020, 12:07pm UTC](https://discourse.gohugo.io/t/render-link-functionality-not-working/26358/6 "2020-06-19T12:07:01Z")

</div>

Try this: Create `layouts/shortcodes/xx.html`:

```auto
{{ $url := .Get 0 | safeURL }}
{{ $findThis := "/redirect/" }}
{{ $hasIt := in $url $findThis }}
{{ $hasItPrefix := strings.HasPrefix $url $findThis }}
{{ $url }}<br />
{{ $hasIt }}<br />
{{ $hasItPrefix }}

```

From your content (either `.md` or `.html`):

```auto
{{< xx "/redirect/external-site/" >}}

```

This _should_ yield:

```auto
/redirect/external-site/
true
true

```

---

<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:** [June 19, 2020, 1:27pm UTC](https://discourse.gohugo.io/t/render-link-functionality-not-working/26358/7 "2020-06-19T13:27:18Z")

</div>

This would be much simpler and more efficient to troubleshoot if you were to post a link to a public repository for your site.

---

<div class="post-metadata">

**Author:** ![ryan77](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/ryan77/32/11666_2.png) [@ryan77](https://discourse.gohugo.io/u/ryan77)\
**Post date:** [June 21, 2020, 12:48am UTC](https://discourse.gohugo.io/t/render-link-functionality-not-working/26358/8 "2020-06-21T00:48:53Z")

</div>

Great idea, here’s the basics:

> **[rs77/hugo-test](https://github.com/rs77/hugo-test)**
>
> Test hugo site. Contribute to rs77/hugo-test development by creating an account on GitHub.

---

<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:** [June 21, 2020, 7:06am UTC](https://discourse.gohugo.io/t/render-link-functionality-not-working/26358/9 "2020-06-21T07:06:57Z")

</div>

This is a bug. I’ll post a follow-up shortly.

---

<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:** [June 21, 2020, 7:20am UTC](https://discourse.gohugo.io/t/render-link-functionality-not-working/26358/10 "2020-06-21T07:20:32Z")

</div>

> <https://github.com/gohugoio/hugo/issues/7416>
>
> What version of Hugo are you using (hugo version)?
> $ hugo version
> Hugo Static Site Generator v0.73.0-DEV/extended linux/amd64 BuildDate: unknown
> Does this issue reproduce...

---

<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:** [June 21, 2020, 7:58pm UTC](https://discourse.gohugo.io/t/render-link-functionality-not-working/26358/11 "2020-06-21T19:58:54Z")

</div>

In your markdown do this:

```auto
[This is a link]({{% relref "/redirect/external-site.md" %}})

```

instead of this:

```auto
[This is a link]({{< relref "/redirect/external-site.md" >}})

```

---

<div class="post-metadata">

**Author:** ![ryan77](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/ryan77/32/11666_2.png) [@ryan77](https://discourse.gohugo.io/u/ryan77)\
**Post date:** [June 22, 2020, 11:22am UTC](https://discourse.gohugo.io/t/render-link-functionality-not-working/26358/12 "2020-06-22T11:22:58Z")

</div>

Thanks Joe, I can confirm that the change has rectified the problem.

Out of curiosity now - what’s the difference between `{{<` and `{{%`?

Thanks again.

---

<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:** [June 23, 2020, 2:39pm UTC](https://discourse.gohugo.io/t/render-link-functionality-not-working/26358/13 "2020-06-23T14:39:40Z")

</div>

I wish this were a trivial question. It is not. The behavior changed in version 0.55, and again in 0.60.

| Version | Shortcode | Markdown | HTML |
| --- | --- | --- | --- |
| `0.54` | `{{ .Inner }}` | `{{< foo >}} **bold** {{< /foo >}}` | ` **bold** ` |
| `0.54` | `{{ .Inner }}` | `{{% foo %}} **bold** {{% /foo %}}` | `<strong>bold</strong>` |
| `0.54` | `<p>{{ .Inner }}</p>` | `{{< foo >}} **bold** {{< /foo >}}` | `<p> **bold** </p>` |
| `0.54` | `<p>{{ .Inner }}</p>` | `{{% foo %}} **bold** {{% /foo %}}` | `<p><strong>bold</strong></p>` |
| &nbsp; | | | |
| `0.55` | `{{ .Inner }}` | `{{< foo >}} **bold** {{< /foo >}}` | ` **bold** ` |
| `0.55` | `{{ .Inner }}` | `{{% foo %}} **bold** {{% /foo %}}` | `<p><strong>bold</strong></p>` |
| `0.55` | `<p>{{ .Inner }}</p>` | `{{< foo >}} **bold** {{< /foo >}}` | `<p> **bold** </p>` |
| `0.55` | `<p>{{ .Inner }}</p>` | `{{% foo %}} **bold** {{% /foo %}}` | `<p> **bold** </p>` |
| &nbsp; | | | |
| `0.60` | `{{ .Inner }}` | `{{< foo >}} **bold** {{< /foo >}}` | ` **bold** ` |
| `0.60` | `{{ .Inner }}` | `{{% foo %}} **bold** {{% /foo %}}` | `<p><strong>bold</strong></p>` |
| `0.60` | `<p>{{ .Inner }}</p>` | `{{< foo >}} **bold** {{< /foo >}}` | `<p> **bold** </p>` |
| `0.60` | `<p>{{ .Inner }}</p>` | `{{% foo %}} **bold** {{% /foo %}}` | `<!-- raw HTML omitted -->` |

Look at the last line.

The `<!-- raw HTML omitted -->` comment is rendered, _without warning during the build_, due to the [security model](https://gohugo.io/about/security-model/#web-application-security) introduced in Hugo 0.60. In this example, to get the desired output…

Shortcode:

```html
<p>{{ .Inner | markdownify }}</p>

```

And then call it with:

```md
{{< foo >}} **bold** {{< /foo >}}

```

So now we’re in the habit of coding our shortcodes templates this way, and always calling them with the `{{< foo >}}` notation. But there’s another big difference between the two notation styles, introduced in Hugo 0.55. From the release notes:

> Shortcodes using the `{{% %}}` as the outer-most delimiter will now be fully rendered when sent to the content renderer (e.g. Blackfriday for Markdown), meaning they can be part of the generated table of contents, footnotes, etc.

I think this change is what makes it possible to do what you originally asked about: using the output of a shortcode within a render hook.

Comments:

1. Prior to deployment we always `grep` the `public` directory for `<!-- raw HTML omitted -->` and `ZgotmplZ` to find problems that Hugo doesn’t warn us about during build.

2. With Hugo 0.62 and later [.RenderString](https://gohugo.io/functions/renderstring/) is preferable to [`markdownify`](https://gohugo.io/functions/markdownify/):

3. The version 0.60 examples assume default settings (i.e., you have not overridden default security settings in `config.toml`).

4. If you find this confusing you are not alone. The existing documentation is insufficient, but I’m not sure anyone understands the functionality/cases well enough to rewrite it.

---

<div class="post-metadata">

**Author:** ![divinerites](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/divinerites/32/12625_2.png) [@divinerites](https://discourse.gohugo.io/u/divinerites)\
**Post date:** [June 23, 2020, 5:47pm UTC](https://discourse.gohugo.io/t/render-link-functionality-not-working/26358/14 "2020-06-23T17:47:37Z")

</div>

> [@jmooring](#):
>
> If you find this confusing you are not alone. The existing documentation is insufficient, but I’m not sure anyone understands the functionality/cases well enough to rewrite it.

Thank you !! I almost went crazy many times (and i think i understand reasonably the hugo philosophy). So when @jmooring says that, it is good for my mental health 🤪

This is the best explanation so far I ever saw. You should put that at minimum in the tip/trick section too.
