diff --git a/content/en/content-management/cross-references.md b/content/en/content-management/cross-references.md index 21a73b861..9570a8fa4 100644 --- a/content/en/content-management/cross-references.md +++ b/content/en/content-management/cross-references.md @@ -15,31 +15,39 @@ aliases: [/extras/crossreferences/] toc: true --- - -The `ref` and `relref` shortcode resolves the absolute or relative permalink given a path to a document. +The `ref` and `relref` shortcodes display the absolute and relative permalinks to a document, respectively. ## Use `ref` and `relref` ```go-html-template +{{* ref "document" */>}} +{{* ref "document#anchor" */>}} {{* ref "document.md" */>}} -{{* ref "#anchor" */>}} {{* ref "document.md#anchor" */>}} +{{* ref "#anchor" */>}} {{* ref "/blog/my-post" */>}} {{* ref "/blog/my-post.md" */>}} +{{* relref "document" */>}} {{* relref "document.md" */>}} {{* relref "#anchor" */>}} -{{* relref "document.md#anchor" */>}} +{{* relref "/blog/my-post.md" */>}} ``` -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. +To generate a hyperlink using `ref` or `relref` in markdown: -**Paths without a leading `/` will first be tried resolved relative to the current page.** +```md +[About]({{* ref "/page/about" */>}} "About Us") +``` -You will get an error if your document could not be uniquely resolved. The error behaviour can be configured, see below. +The `ref` and `relref` shortcodes require a single parameter: the path to a content document, with or without a file extension, with or without an anchor. + +**Paths without a leading `/` are first resolved relative to the current page, then to the remainder of the site. + +Hugo emits an error or warning if a document cannot be uniquely resolved. The error behavior is configurable; see below. ### Link to another language version -Link to another language version of a document, you need to use this syntax: +To link to another language version of a document, use this syntax: ```go-html-template {{* relref path="document.md" lang="ja" */>}} @@ -47,45 +55,66 @@ Link to another language version of a document, you need to use this syntax: ### Get another Output Format -To link to a given Output Format of a document, you can use this syntax: +To link to another Output Format of a document, use this syntax: ```go-html-template {{* relref path="document.md" outputFormat="rss" */>}} ``` -### Anchors +### Heading IDs -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: +When using Markdown document types, Hugo generates element IDs for every heading on a page. For example: -```go-html-template -{{* relref "#anchors" */>}} => #anchors:9decaf7 +```md +## Reference ``` -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 +produces this HTML: -```go-html-template -{{* relref "#who" */>}} => #who:9decaf7 -{{* relref "/blog/post.md#who" */>}} => /blog/post/#who:badcafe +```html +