hugo/docs/content/en/functions/urls/Ref.md
2023-10-20 09:43:56 +02:00

1.6 KiB

title linkTitle description categories keywords menu function relatedFunctions aliases
urls.Ref ref Returns the absolute permalink to a page.
functions
docs
parent
functions
aliases returnType signatures
ref
template.HTML
urls.Ref . PAGE
urls.Ref
urls.RelRef
/functions/ref

This function takes two arguments:

  • 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.
{{ ref . "about" }}
{{ ref . "about#anchor" }}
{{ ref . "about.md" }}
{{ ref . "about.md#anchor" }}
{{ ref . "#anchor" }}
{{ ref . "/blog/my-post" }}
{{ ref . "/blog/my-post.md" }}

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

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

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

{{ ref . (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 ref shortcode. For a detailed explanation of how to leverage this shortcode for content management, see Links and Cross References.