hugo/docs/content/en/content-management/cross-references.md

89 lines
2.9 KiB
Markdown
Raw Normal View History

---
title: Links and Cross References
2018-07-19 15:02:03 +00:00
description: Shortcodes for creating links to documents.
date: 2017-02-01
publishdate: 2017-02-01
lastmod: 2017-03-31
categories: [content management]
keywords: ["cross references","references", "anchors", "urls"]
menu:
docs:
parent: "content-management"
weight: 100
weight: 100 #rem
aliases: [/extras/crossreferences/]
toc: true
---
2018-07-19 15:02:03 +00:00
The `ref` and `relref` shortcode resolves the absolute or relative permalink given a path to a document.
## Use `ref` and `relref`
2018-07-19 15:02:03 +00:00
```go-html-template
{{</* ref "document.md" */>}}
{{</* ref "#anchor" */>}}
{{</* ref "document.md#anchor" */>}}
2018-07-19 15:02:03 +00:00
{{</* ref "/blog/my-post" */>}}
{{</* ref "/blog/my-post.md" */>}}
{{</* relref "document.md" */>}}
{{</* relref "#anchor" */>}}
{{</* relref "document.md#anchor" */>}}
```
2018-07-19 15:02:03 +00: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.
2018-07-19 15:02:03 +00:00
**Paths without a leading `/` will first be tried resolved relative to the current page.**
2018-07-19 15:02:03 +00:00
You will get an error if you document could not be uniquely resolved. The error behaviour can be configured, see below.
2018-07-19 15:02:03 +00:00
### Link to another language version
2018-07-19 15:02:03 +00:00
Link to another language version of a document, you need to use this syntax:
2018-07-19 15:02:03 +00:00
```go-html-template
{{</* relref path="document.md" lang="jp" */>}}
```
2018-07-19 15:02:03 +00:00
### Get another Output Format
2018-07-19 15:02:03 +00:00
To link to a given Output Format of a document, you can use this syntax:
2018-07-19 15:02:03 +00:00
```go-html-template
{{</* relref path="document.md" outputFormat="rss" */>}}
```
### Anchors
When an `anchor` is provided by itself, the current pages unique identifier will be appended; when an `anchor` is provided appended to `documentname`, the found page's unique identifier will be appended:
2018-07-19 15:02:03 +00:00
```go-html-template
{{</* 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-07-19 15:02:03 +00:00
```go-html-template
{{</* relref "#who" */>}} => #who:9decaf7
2018-07-19 15:02:03 +00:00
{{</* relref "/blog/post.md#who" */>}} => /blog/post/#who:badcafe
```
More information about document unique identifiers and headings can be found [below]({{< ref "#hugo-heading-anchors" >}}).
## Ref and RelRef Configuration
The behaviour can, since Hugo 0.45, be configured in `config.toml`:
refLinksErrorLevel ("ERROR")
: When using `ref` or `relref` to resolve page links and a link cannot resolved, it will be logged with this logg level. Valid values are `ERROR` (default) or `WARNING`. Any `ERROR` will fail the build (`exit -1`).
refLinksNotFoundURL
: URL to be used as a placeholder when a page reference cannot be found in `ref` or `relref`. Is used as-is.
[lists]: /templates/lists/
[output formats]: /templates/output-formats/
[shortcode]: /content-management/shortcodes/
Squashed 'docs/' changes from 715741f73..4e7e1815b 4e7e1815b Fix some typos d23d8f5c4 Remove 'fundamentals' category from function pages 52fa65e15 Mention Chroma as the preferred syntax highlighter 64ca535db Merge commit '8762aee8afe30bec6f1fbc9560749983dc44d60b' 8762aee8a Squashed 'themes/gohugoioTheme/' changes from 396b859f..6f3a8bf5 03f0673a9 Move the gopher to the theme 320e268cd Spelling e45b640f7 More layout lookup work fe0ad9d9d Sync the YAML config menu example with TOML's b9505fc70 Remove template reference to ordinal numbers 0fa2532d3 Remove deprecated Hugoidx, add native hugo solution 2152b907c Fix a link in the last commit 47614f416 Manually specifying heading anchors in Markdown content 9d6770d2a Release notes 0.37.1 e1eed8b27 Remove some unused images e960046f5 releaser: Prepare repository for 0.38-DEV 4fa83a4ee releaser: Add release notes to /docs for release of 0.37.1 46c879995 releaser: Bump versions for release of 0.37.1 fb3ac5a3e releaser: Prepare repository for 0.38-DEV 4870c8e7b Update archetypes.md 232c0b578 Merge commit '2b18014fd0aa99e9f1a5610ba875101351a90de3' 2b18014fd Squashed 'themes/gohugoioTheme/' changes from fe71e360..396b859f 62567e9aa Add some "writing guidelines" 7cfd530d2 Revise the archetype docs 5d4c3c03c Update data-templates.md e5fee3099 Update page-bundles.md ca7f03c8d Update page-bundles.md 2a7fdc269 Fix typo 'vailable' to 'available' line 53 999b75201 LastMod should be Lastmod? 099f46ca5 Fix spacing in content-management/types.md 6bcdc58ef Word choice improvements 20e8a21f6 update rss linking docs 7ef44d262 Add some missing configuration entries f1c7aa568 Sort config list 5cb8ceade Create a proper definition list for the configuration settings 25dffe4ac Send custom dimensions in GA 55df01a34 Fix broken gtag 6c8772aad Add site to GA config e63acb894 Remove conflicting release note for 0.35 f30083a23 Add branch to GA config 99caedb96 Set the small-multiples to draft 4a33c70ab Polish the Small Multiples showcase 7b2f1ea2e Add small multiples showcase e78e96bae Add new sponsor c42943041 updated to new Forestry logo e07eda273 Add OS env to faq 414f0dbc6 Release Hugo 0.37 85f0cc324 Merge branch 'temp37' 1e6da9497 Rebuild images 75e97adfc releaser: Add release notes to /docs for release of 0.37 50b887cb0 releaser: Bump versions for release of 0.37 7acf73ba3 Merge commit '900b5f6cfe5a377ef369d26cd700201be4cf6b06' 819d02c30 Merge commit '374d184e6747678364fd61f5faf328ec9205eb6b' c7eacf018 Fix typos in development contribution doc git-subtree-dir: docs git-subtree-split: 4e7e1815b742659dec1c8f59a1896a3396c7b6e9
2018-03-11 19:39:20 +00:00
[bfext]: /content-management/formats/#blackfriday-extensions