2019-10-21 04:22:28 -04:00
---
2023-10-20 03:42:39 -04:00
title: urls.Ref
2023-12-04 09:14:18 -05:00
description: Returns the absolute permalink to a page at the given path.
categories: []
2023-10-20 03:42:39 -04:00
keywords: []
2023-12-04 09:14:18 -05:00
action:
2023-10-20 03:42:39 -04:00
aliases: [ref]
2023-12-04 09:14:18 -05:00
related:
- functions/urls/RelRef
- methods/page/Ref
- methods/page/RelRef
returnType: string
signatures:
- urls.Ref PAGE PATH
- urls.Ref PAGE OPTIONS
2023-10-20 03:42:39 -04:00
aliases: [/functions/ref]
2019-10-21 04:22:28 -04:00
---
2023-12-04 09:14:18 -05:00
The first argument is the context of the page from which to resolve relative paths, typically the current page.
2019-10-21 04:22:28 -04:00
2023-12-04 09:14:18 -05:00
The second argument is a 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. Alternatively, provide an [options map ](#options ) instead of a path.
2020-09-07 15:37:51 -04:00
```go-html-template
{{ ref . "about" }}
{{ ref . "about#anchor" }}
2019-10-21 04:22:28 -04:00
{{ ref . "about.md" }}
2020-09-07 15:37:51 -04:00
{{ ref . "about.md#anchor" }}
{{ ref . "#anchor" }}
{{ ref . "/blog/my-post" }}
{{ ref . "/blog/my-post.md" }}
2019-10-21 04:22:28 -04:00
```
2023-12-04 09:14:18 -05:00
## Options
Instead of specifying a path, you can also provide an options map:
path
: (`string`) The path to the page, relative to the content directory. Required.
lang
: (`string`) The language (site) to search for the page. Default is the current language. Optional.
outputFormat
: (`string`) The output format to search for the page. Default is the current output format. Optional.
2020-09-07 15:37:51 -04:00
To return the absolute permalink to another language version of a page:
```go-html-template
{{ ref . (dict "path" "about.md" "lang" "fr") }}
```
2019-10-21 04:22:28 -04:00
2020-09-07 15:37:51 -04:00
To return the absolute permalink to another Output Format of a page:
2020-01-05 05:13:09 -05:00
2020-09-07 15:37:51 -04:00
```go-html-template
{{ ref . (dict "path" "about.md" "outputFormat" "rss") }}
2020-01-05 05:13:09 -05:00
```
2023-12-04 09:14:18 -05:00
By default, Hugo will throw an error and fail the build if it cannot resolve the path. You can change this to a warning in your site configuration, and specify a URL to return when the path cannot be resolved.
2019-10-21 04:22:28 -04:00
2023-12-04 09:14:18 -05:00
{{< code-toggle file = hugo > }}
refLinksErrorLevel = 'warning'
refLinksNotFoundURL = '/some/other/url'
{{< / code-toggle > }}