hugo/content/en/functions/relref.md
Bjørn Erik Pedersen 7d7771b673 Squashed 'docs/' changes from 7297c1172..d3eb97a33
d3eb97a33 Document .IsSection page variable
a068bcf5c Ace and Amber support was removed with #6609
5cd9ca4b2 Mention MacPorts also on the Installing page  (#1215)
0ae8f5c19 Add instructions for using Macports
d50aba8f0 Revise ref and relref function pages
a17e25d6f Update quick-start.md: move notice about drafts up
cf87a5da2 Update macOS tarball installation instructions (#1203)
2e701f8f3 Corrected the url for index function link
736bd59e0 Clarify treatment of zero weights (#1207)
42a19f479 Fix example of output from urlize function
34f8de26d Revise content-management/cross-references
252435a95 Rewrite Translation of Strings
f0882bc14 Remove note that has been outdated by v0.71.0
dfe28ceb5 Improve mounts module config
58029627d Fix erroneous example code piping to if

git-subtree-dir: docs
git-subtree-split: d3eb97a3328f5390801bbce017233ce895fc2d28
2020-09-07 21:37:51 +02:00

2 KiB

title linktitle description godocref date publishdate lastmod categories menu keywords signature workson hugoversion relatedfuncs deprecated aliases
relref relref Returns the relative permalink to a page. 2017-02-01 2017-02-01 2020-09-05
functions
docs
parent
functions
cross references
anchors
relref . PAGE
ref
false

This function takes two parameters:

  • The context of the page from which to resolve relative paths, typically the current page (.)
  • The path to a page, with or without a file extension, with or without an anchor. A path without a leading / is first resolved relative to the given context, then to the remainder of the site.
{{ relref . "about" }}
{{ relref . "about#anchor" }}
{{ relref . "about.md" }}
{{ relref . "about.md#anchor" }}
{{ relref . "#anchor" }}
{{ relref . "/blog/my-post" }}
{{ relref . "/blog/my-post.md" }}

The permalink returned is relative to the protocol+host portion of the baseURL specified in the site configuration. For example:

Code baseURL Permalink
{{ relref . "/about" }} http://example.org/ /about/
{{ relref . "/about" }} http://example.org/x/ /x/about/

To return the relative permalink to another language version of a page:

{{ relref . (dict "path" "about.md" "lang" "fr") }}

To return the relative permalink to another Output Format of a page:

{{ relref . (dict "path" "about.md" "outputFormat" "rss") }}

Hugo emits an error or warning if the page cannot be uniquely resolved. The error behavior is configurable; see Ref and RelRef Configuration.

This function is used by Hugo's built-in relref shortcode. For a detailed explanation of how to leverage this shortcode for content management, see Links and Cross References.