fcc3ed651 Remove some expired new-in a9c5981f5 Fix cascade example 82bb250fa Add some lines about permalinks tokens in front matter 328fe564e Remove some outdated new-in fb140b153 Hide showcase menu entry 42d9d1c79 Update image formats from which EXIF data can be extracted 09ad56b6e netlify: Hugo 0.130.0 1d503f846 Merge branch 'tempv0.130.0' e2458074d math: Add trigonometric functions and some angle helper functions 392afc8f9 Disable the showcase section for now 0300750f2 Improve example of image render hook 60a9306af Improve description of the .Site.RegularPages method 8d759175d Fix typos 55daa4554 Update XxHash.md 397c81cb7 Add namespace for hash functions 70fe8d2f0 netlify: Bump Hugo 0.129.0 5a9771aff Merge branch 'tempv0.129.0' f9146575b Fix typo e6e1fea49 Fix typo in Hugo docs | functions | partial 732d10ec4 source: Expose GitInfo Body 34c97e639 netlify: Hugo 0.128.2 3270587e9 Fix typo 727c5396e netlify: Hugo 0.128.1 80b6ae99c Update GitHub Pages workflow file example 027134102 Update GitHub Pages workflow file example 2600a8a2e Miscellaneous edits 3fdd5819b Update Build.md 7764005c3 Improve example of render hook directory structure 5e3941d82 Fix typos 748bf065f Restructure templates section fafbf6566 Update Defer.md 012162e0d Document changes to template functions in v0.128.0 0990ce35b quick-reference: Update emojis 6677a30ef Update Goldmark configuration documentation 4449d530d Document new pagination config 0af8be439 Update Defer.md 56348196d netlify: Hugo 0.128.0 d67b6d82e Update content/en/functions/templates/Defer.md 23d996b3d Update content/en/functions/templates/Defer.md 7f7fb2f27 Document templates.Defer 5ada1e9d5 Fix docs merge (remove shortcode) d27ee6156 Merge branch 'tempv0.128.0' 5d7317c84 Fix typo 7c18ee546 Update theme 83bfea63b Update theme b274b3238 Merge commit '8b9803425e63e1b1801f8d5d676e96368d706722' ff34a035a deploy: Add stripIndexHtml target option d9e964bdb markup/goldmark: Add the Hugo Goldmark Extras "delete" extension ac5bd16d2 deps: Upgrade github.com/alecthomas/chroma v2.13.0 => v2.14.0 25377171b config: Remove extraneous BuildConfig setting 0d2044f6d docs: Regen docshelper a2548dac9 markup/goldmark: Support extras extension 9d0c86ee8 commands: Add gen chromastyles --lineNumbersTableStyle flag git-subtree-dir: docs git-subtree-split: fcc3ed651a1b6431303c2f88f20fa38531c52b3d
4.1 KiB
title | description | categories | keywords | menu | weight | toc | aliases | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Links and cross references | Shortcodes for creating links to documents. |
|
|
|
170 | true |
|
The ref
and relref
shortcodes display the absolute and relative permalinks to a document, respectively.
Use of ref
and relref
The ref
and relref
shortcodes require a single argument: 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.
.
└── content
├── about
| ├── _index.md
| └── credits.md
├── pages
| ├── document1.md
| └── document2.md // has anchor #anchor
├── products
| └── index.md
└── blog
└── my-post.md
The pages can be referenced as follows:
{{</* ref "document2" */>}} <-- From pages/document1.md, relative path
{{</* ref "document2#anchor" */>}}
{{</* ref "document2.md" */>}}
{{</* ref "document2.md#anchor" */>}}
{{</* ref "#anchor" */>}} <-- From pages/document2.md
{{</* ref "/blog/my-post" */>}} <-- From anywhere, absolute path
{{</* ref "/blog/my-post.md" */>}}
{{</* relref "document" */>}}
{{</* relref "document.md" */>}}
{{</* relref "#anchor" */>}}
{{</* relref "/blog/my-post.md" */>}}
index.md can be reference either by its path or by its containing folder without the ending /
. _index.md can be referenced only by its containing folder:
{{</* ref "/about" */>}} <-- References /about/_index.md
{{</* ref "/about/_index" */>}} <-- Raises REF_NOT_FOUND error
{{</* ref "/about/credits.md" */>}} <-- References /about/credits.md
{{</* ref "/products" */>}} <-- References /products/index.md
{{</* ref "/products/index" */>}} <-- References /products/index.md
To generate a hyperlink using ref
or relref
in Markdown:
[About]({{</* ref "/about" */>}} "About Us")
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
Using ref
or relref
without specifying a language, will make the reference resolve to the language of the current content page.
To link to another language version of a document, use this syntax:
{{</* relref path="document.md" lang="ja" */>}}
Get another output format
To link to another Output Format of a document, use this syntax:
{{</* relref path="document.md" outputFormat="rss" */>}}
Heading IDs
When using Markdown document types, Hugo generates element IDs for every heading on a page. For example:
## Reference
produces this HTML:
<h2 id="reference">Reference</h2>
Get the permalink to a heading by appending the ID to the path when using the ref
or relref
shortcodes:
{{</* ref "document.md#reference" */>}}
{{</* relref "document.md#reference" */>}}
Generate a custom heading ID by including an attribute. For example:
## Reference A {#foo}
## Reference B {id="bar"}
produces this HTML:
<h2 id="foo">Reference A</h2>
<h2 id="bar">Reference B</h2>
Hugo will generate unique element IDs if the same heading appears more than once on a page. For example:
## Reference
## Reference
## Reference
produces this HTML:
<h2 id="reference">Reference</h2>
<h2 id="reference-1">Reference</h2>
<h2 id="reference-2">Reference</h2>
Ref and RelRef Configuration
The behavior can be configured in hugo.toml
:
- refLinksErrorLevel ("ERROR")
- When using
ref
orrelref
to resolve page links and a link cannot resolved, it will be logged with this log level. Valid values areERROR
(default) orWARNING
. AnyERROR
will fail the build (exit -1
). - refLinksNotFoundURL
- URL to be used as a placeholder when a page reference cannot be found in
ref
orrelref
. Is used as-is.