hugo/content/content-management/cross-references.md
Bjørn Erik Pedersen 374d184e67 Squashed 'docs/' changes from f97826a17..1dc05a16b
1dc05a16b Update index.md
d73a9b3b4 Added StackImpact showcase
b0e82b3a5 Fix uglyURLs example
cf8a93728 GA track outgoing sponsor clikcs
aca59ac66 Move the sponsor banners up a little
5571673f0 Migrate from analytics.js to gtag.js
64a29b6cb Update faq.md
84704aa84 Use GOPATH variable if defined in installation from source
5f70e6ee2 Remove disableRSS etc. from the documentation
4945e7937 Remove superflous asterisks
39f6c9c28 showcase: Add 1password.com
fe0f82610 Add GitLab warning
9f26f21d2 Fix URL typo
83a91fc99 Remove duplicate release notes
133cdd313 Release 0.36.1
fbe2a2dc7 Clean images
1b02f9193 Merge branch 'temp361'
c430d2d58 Merge branch 'release-0.36.1'
dd7370fc4 releaser: Prepare repository for 0.37-DEV
72534f9ec releaser: Add release notes to /docs for release of 0.36.1
845b2cacb releaser: Bump versions for release of 0.36.1
78790fcb1 Add fluid type to showcase details box
4ef59e008 Adjust column widths to handle a wider variety of copy width
6d2e68521 Always show the latest showcase item on front page
665b1eb5e showcase: Shuffle the news items
5fef1f9b7 Escape quote
d680f0c16 Add some quotes
1722f0d5a showcase: Make the description more about Hugo
a9d43db0a Add Quiply Employee Communications App
7aaa464ec Add Quiply Employee Communications App
fad6a25dd maintenance: Show last 30
7afcfdced showcase: Set Linode date to today
0c31f481a New showcase for Linode
6c7687c2d Minor edits to the `apply` documentation
04bbff8b3 Update apply.md
f543032e3 Fix clunky sentence
218ba2a65 Some more Netlify improvements
0bd512125 Improve the Netlify versioning docs
7a708d60e Clarify Netlify's Hugo versions handling
8f86342cd Add some space
d68d4ff37 Remove now superflous warning
bf93a46ea maintenance: Add TODO list
3b5f27835 maintenance: Remove a superflous prefix
8f29ba2fb maintenance: Adjust order
105d53610 maintenance: Add TOC
29e86396b maintenance: Fix page list selection
ba51fe66d Finish the Maintenance  section
e9b0c710c Add latest changes in new spotlight section
8ccd79f61 Fix broken sentence
c77643c37 Spelling
919f2faef Remove some old troubleshooting articles
09e467f06 Add a new FAQ
ac2b25bb5 Hartwell showcase typos
5bf766993 Trim "www." from shocase URLs in title
a180cd5cb Make the inline showcase template names unique
6886982fd Merge commit '9cc9bab46288d8d5f9fda7009c5f746258cec1b4'
09728efbf Add "target" and "rel" parameters to figure shortcode

git-subtree-dir: docs
git-subtree-split: 1dc05a16bd6b99809d97daeda743d914297f908c
2018-02-21 10:00:31 +01:00

4.8 KiB
Raw Blame History

title description date publishdate lastmod categories keywords menu weight aliases toc
Links and Cross References Hugo makes it easy to link documents together. 2017-02-01 2017-02-01 2017-03-31
content management
cross references
references
anchors
urls
docs
parent weight
content-management 100
100
/extras/crossreferences/
true

The ref and relref shortcodes link documents together, both of which are built-in Hugo shortcodes. These shortcodes are also used to provide links to headings inside of your content, whether across documents or within a document. The only difference between ref and relref is whether the resulting URL is absolute (http://1.com/about/) or relative (/about/), respectively.

Use ref and relref

{{</* ref "document.md" */>}}
{{</* ref "#anchor" */>}}
{{</* ref "document.md#anchor" */>}}
{{</* relref "document.md" */>}}
{{</* relref "#anchor" */>}}
{{</* relref "document.md#anchor" */>}}

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.

Document Names

The documentname is the name of a document, including the format extension; this may be just the filename, or the relative path from the content/ directory. With a document content/blog/post.md, either format will produce the same result:

{{</* relref "blog/post.md" */>}} => `/blog/post/`
{{</* relref "post.md" */>}} => `/blog/post/`

If you have the same filename used across multiple sections, you should only use the relative path format; otherwise, the behavior will be undefined. This is best illustrated with an example content directory:

.
└── content
    ├── events
    │   └── my-birthday.md
    ├── galleries
    │   └── my-birthday.md
    ├── meta
    │   └── my-article.md
    └── posts
        └── my-birthday.md

To be sure to get the correct reference in this case, use the full path:

{{< code file="content/meta/my-article.md" copy="false" >}} {{</* relref "events/my-birthday.md" */>}} => /events/my-birthday/ {{< /code >}}

With Multiple Output Formats

If the page exists in multiple output formats, ref or relref can be used with a output format name:

 [Neat]({{</* ref "blog/neat.md" "amp" */>}})

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:

{{</* relref "#anchors" */>}} => #anchors:9decaf7
{{</* relref "about-hugo/hugo-features.md#content" */>}} => /blog/post/#who:badcafe

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

{{</* relref "#who" */>}} => #who:9decaf7
{{</* 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" >}}).

Examples

  • {{</* ref "blog/post.md" */>}} => https://example.com/blog/post/
  • {{</* ref "post.md#tldr" */>}} => https://example.com/blog/post/#tldr:caffebad
  • {{</* relref "post.md" */>}} => /blog/post/
  • {{</* relref "blog/post.md#tldr" */>}} => /blog/post/#tldr:caffebad
  • {{</* ref "#tldr" */>}} => #tldr:badcaffe
  • {{</* relref "#tldr" */>}} => #tldr:badcaffe

Hugo Heading Anchors

When using Markdown document types, Hugo generates heading anchors automatically. The generated anchor for this section is hugo-heading-anchors. Because the heading anchors are generated automatically, Hugo takes some effort to ensure that heading anchors are unique both inside a document and across the entire site.

Ensuring heading uniqueness across the site is accomplished with a unique identifier for each document based on its path. Unless a document is renamed or moved between sections in the filesystem, the unique identifier for the document will not change: blog/post.md will always have a unique identifier of 81df004c333b392d34a49fd3a91ba720.

ref and relref were added so you can make these reference links without having to know the documents unique identifier. (The links in document tables of contents are automatically up-to-date with this value.)

{{</* relref "content-management/cross-references.md#hugo-heading-anchors" */>}}
/content-management/cross-references/#hugo-heading-anchors:77cd9ea530577debf4ce0f28c8dca242