hugo

Fork of github.com/gohugoio/hugo with reverse pagination support

git clone git://git.shimmy1996.com/hugo.git

relref.md (1994B)

    1 ---
    2 title: relref
    3 linktitle: relref
    4 description: Returns the relative permalink to a page.
    5 date: 2017-02-01
    6 publishdate: 2017-02-01
    7 lastmod: 2020-09-05
    8 categories: [functions]
    9 menu:
   10   docs:
   11     parent: "functions"
   12 keywords: [cross references, anchors]
   13 signature: ["relref . PAGE"]
   14 workson: []
   15 hugoversion:
   16 relatedfuncs: [ref]
   17 deprecated: false
   18 aliases: []
   19 ---
   20 
   21 This function takes two parameters:
   22 
   23 - The context of the page from which to resolve relative paths, typically the current page (`.`)
   24 - 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.
   25 
   26 ```go-html-template
   27 {{ relref . "about" }}
   28 {{ relref . "about#anchor" }}
   29 {{ relref . "about.md" }}
   30 {{ relref . "about.md#anchor" }}
   31 {{ relref . "#anchor" }}
   32 {{ relref . "/blog/my-post" }}
   33 {{ relref . "/blog/my-post.md" }}
   34 ```
   35 
   36 The permalink returned is relative to the protocol+host portion of the baseURL specified in the site configuration. For example:
   37 
   38 Code|baseURL|Permalink
   39 :--|:--|:--
   40 `{{ relref . "/about" }}`|`http://example.org/`|`/about/`
   41 `{{ relref . "/about" }}`|`http://example.org/x/`|`/x/about/`
   42 
   43 To return the relative permalink to another language version of a page:
   44 
   45 ```go-html-template
   46 {{ relref . (dict "path" "about.md" "lang" "fr") }}
   47 ```
   48 
   49 To return the relative permalink to another Output Format of a page:
   50 
   51 ```go-html-template
   52 {{ relref . (dict "path" "about.md" "outputFormat" "rss") }}
   53 ```
   54 
   55 Hugo emits an error or warning if the page cannot be uniquely resolved. The error behavior is configurable; see [Ref and RelRef Configuration](/content-management/cross-references/#ref-and-relref-configuration). 
   56 
   57 This function is used by Hugo's built-in [`relref`](/content-management/shortcodes/#ref-and-relref) shortcode. For a detailed explanation of how to leverage this shortcode for content management, see [Links and Cross References](/content-management/cross-references/).