| 1 |
--- |
| 2 |
title: Ref shortcode |
| 3 |
linkTitle: Ref |
| 4 |
description: Insert a permalink to the given page reference using the ref shortcode. |
| 5 |
categories: [] |
| 6 |
keywords: [] |
| 7 |
--- |
| 8 |
|
| 9 |
> [!NOTE] |
| 10 |
> To override Hugo's embedded `ref` shortcode, copy the [source code][] to a file with the same name in the `layouts/_shortcodes` directory. |
| 11 |
|
| 12 |
> [!NOTE] |
| 13 |
> When working with Markdown this shortcode is obsolete. Instead, to properly resolve Markdown link destinations, use the [embedded link render hook][] or create your own. |
| 14 |
> |
| 15 |
> In its default configuration, Hugo automatically uses the embedded link render hook for multilingual single-host projects, specifically when the [duplication of shared page resources][] feature is disabled. This is the default behavior for such projects. If custom link render hooks are defined by your project, modules, or themes, these will be used instead. |
| 16 |
> |
| 17 |
> You can also configure Hugo to `always` use the embedded link render hook, use it only as a `fallback`, or `never` use it. See [details][]. |
| 18 |
|
| 19 |
## Usage |
| 20 |
|
| 21 |
The `ref` shortcode accepts either a single positional argument (the path) or one or more named arguments, as listed below. |
| 22 |
|
| 23 |
## Arguments |
| 24 |
|
| 25 |
{{% include "_common/ref-and-relref-options.md" %}} |
| 26 |
|
| 27 |
## Examples |
| 28 |
|
| 29 |
The `ref` shortcode typically provides the destination for a Markdown link. |
| 30 |
|
| 31 |
> [!NOTE] |
| 32 |
> Always use [Markdown notation][] notation when calling this shortcode. |
| 33 |
|
| 34 |
The following examples show the rendered output for a page on the English version of the site: |
| 35 |
|
| 36 |
```md |
| 37 |
[Link A]({{%/* ref "/books/book-1" */%}}) |
| 38 |
|
| 39 |
[Link B]({{%/* ref path="/books/book-1" */%}}) |
| 40 |
|
| 41 |
[Link C]({{%/* ref path="/books/book-1" lang="de" */%}}) |
| 42 |
|
| 43 |
[Link D]({{%/* ref path="/books/book-1" lang="de" outputFormat="json" */%}}) |
| 44 |
``` |
| 45 |
|
| 46 |
Rendered: |
| 47 |
|
| 48 |
```html |
| 49 |
<a href="https://example.org/en/books/book-1/">Link A</a> |
| 50 |
|
| 51 |
<a href="https://example.org/en/books/book-1/">Link B</a> |
| 52 |
|
| 53 |
<a href="https://example.org/de/books/book-1/">Link C</a> |
| 54 |
|
| 55 |
<a href="https://example.org/de/books/book-1/index.json">Link D</a> |
| 56 |
``` |
| 57 |
|
| 58 |
## Error handling |
| 59 |
|
| 60 |
{{% include "_common/ref-and-relref-error-handling.md" %}} |
| 61 |
|
| 62 |
[Markdown notation]: /content-management/shortcodes/#notation |
| 63 |
[details]: /configuration/markup/#renderhookslinkuseembedded |
| 64 |
[duplication of shared page resources]: /configuration/markup/#duplicateresourcefiles |
| 65 |
[embedded link render hook]: /render-hooks/links/#embedded |
| 66 |
[source code]: <{{% eturl ref %}}> |