2017-08-10 11:18:22 -04:00
---
2017-10-15 04:20:55 -04:00
title: Links and Cross References
2018-08-01 04:01:05 -04:00
description: Shortcodes for creating links to documents.
2017-08-10 11:18:22 -04:00
date: 2017-02-01
publishdate: 2017-02-01
lastmod: 2017-03-31
categories: [content management]
2017-09-21 13:03:00 -04:00
keywords: ["cross references","references", "anchors", "urls"]
2017-08-10 11:18:22 -04:00
menu:
docs:
parent: "content-management"
weight: 100
weight: 100 #rem
aliases: [/extras/crossreferences/]
toc: true
---
2018-08-01 04:01:05 -04:00
The `ref` and `relref` shortcode resolves the absolute or relative permalink given a path to a document.
2017-08-10 11:18:22 -04:00
## Use `ref` and `relref`
2018-08-01 04:01:05 -04:00
```go-html-template
2017-10-04 03:27:29 -04:00
{{< /* ref "document.md" */>}}
2017-08-10 11:18:22 -04:00
{{< /* ref "#anchor" */>}}
2017-10-04 03:27:29 -04:00
{{< /* ref "document.md#anchor" */>}}
2018-08-01 04:01:05 -04:00
{{< /* ref "/blog/my-post" */>}}
{{< /* ref "/blog/my-post.md" */>}}
2017-10-04 03:27:29 -04:00
{{< /* relref "document.md" */>}}
2017-08-10 11:18:22 -04:00
{{< /* relref "#anchor" */>}}
2017-10-04 03:27:29 -04:00
{{< /* relref "document.md#anchor" */>}}
2017-08-10 11:18:22 -04:00
```
2018-08-01 04:01:05 -04:00
The single parameter to `ref` is a string with a content `documentname` (e.g., `about.md` ) with or without an appended in-document `anchor` (`#who`) without spaces. Hugo is flexible in how we search for documents, so the file suffix may be omitted.
2017-08-10 11:18:22 -04:00
2018-08-01 04:01:05 -04:00
**Paths without a leading `/` will first be tried resolved relative to the current page.**
2017-08-10 11:18:22 -04:00
2019-02-01 03:01:04 -05:00
You will get an error if your document could not be uniquely resolved. The error behaviour can be configured, see below.
2017-08-10 11:18:22 -04:00
2018-08-01 04:01:05 -04:00
### Link to another language version
2017-08-10 11:18:22 -04:00
2018-08-01 04:01:05 -04:00
Link to another language version of a document, you need to use this syntax:
2017-08-10 11:18:22 -04:00
2018-08-01 04:01:05 -04:00
```go-html-template
2018-10-29 04:19:20 -04:00
{{< /* relref path="document.md" lang="ja" */>}}
2017-08-10 11:18:22 -04:00
```
2018-08-01 04:01:05 -04:00
### Get another Output Format
2017-08-10 11:18:22 -04:00
2018-08-01 04:01:05 -04:00
To link to a given Output Format of a document, you can use this syntax:
2017-08-10 11:18:22 -04:00
2018-08-01 04:01:05 -04:00
```go-html-template
{{< /* relref path="document.md" outputFormat="rss" */>}}
2017-08-10 11:18:22 -04:00
```
### Anchors
When an `anchor` is provided by itself, the current page’ s unique identifier will be appended; when an `anchor` is provided appended to `documentname` , the found page's unique identifier will be appended:
2018-08-01 04:01:05 -04:00
```go-html-template
2017-08-10 11:18:22 -04:00
{{< /* relref "#anchors" */>}} => #anchors:9decaf7
```
The above examples render as follows for this very page as well as a reference to the "Content" heading in the Hugo docs features pageyoursite
2018-08-01 04:01:05 -04:00
```go-html-template
2017-08-10 11:18:22 -04:00
{{< /* relref "#who" */>}} => #who:9decaf7
2018-08-01 04:01:05 -04:00
{{< /* relref "/blog/post.md#who" */>}} => /blog/post/#who:badcafe
2017-08-10 11:18:22 -04:00
```
More information about document unique identifiers and headings can be found [below ]({{< ref "#hugo-heading-anchors" >}} ).
2018-08-01 04:01:05 -04:00
## Ref and RelRef Configuration
2017-08-10 11:18:22 -04:00
2018-08-01 04:01:05 -04:00
The behaviour can, since Hugo 0.45, be configured in `config.toml` :
2017-08-10 11:18:22 -04:00
2018-08-01 04:01:05 -04:00
refLinksErrorLevel ("ERROR")
2019-03-26 13:41:09 -04:00
: When using `ref` or `relref` to resolve page links and a link cannot resolved, it will be logged with this log level. Valid values are `ERROR` (default) or `WARNING` . Any `ERROR` will fail the build (`exit -1`).
2017-08-10 11:18:22 -04:00
2018-08-01 04:01:05 -04:00
refLinksNotFoundURL
: URL to be used as a placeholder when a page reference cannot be found in `ref` or `relref` . Is used as-is.
2017-08-10 11:18:22 -04:00
[lists]: /templates/lists/
[output formats]: /templates/output-formats/
2017-10-04 03:27:29 -04:00
[shortcode]: /content-management/shortcodes/
2018-03-11 15:39:20 -04:00
[bfext]: /content-management/formats/#blackfriday-extensions