| 1 |
--- |
| 2 |
title: urls.RelRef |
| 3 |
description: Returns the relative URL of the page with the given path, language, and output format. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
aliases: [relref] |
| 9 |
returnType: string |
| 10 |
signatures: |
| 11 |
- urls.RelRef PAGE PATH |
| 12 |
- urls.RelRef PAGE OPTIONS |
| 13 |
aliases: [/functions/relref] |
| 14 |
--- |
| 15 |
|
| 16 |
## Usage |
| 17 |
|
| 18 |
The `relref` function takes two arguments: |
| 19 |
|
| 20 |
1. The context for resolving relative paths (typically the current page). |
| 21 |
1. Either the target page's path or an options map (see below). |
| 22 |
|
| 23 |
## Options |
| 24 |
|
| 25 |
{{% include "_common/ref-and-relref-options.md" %}} |
| 26 |
|
| 27 |
## Examples |
| 28 |
|
| 29 |
The following examples show the rendered output for a page on the English version of the site: |
| 30 |
|
| 31 |
```go-html-template |
| 32 |
{{ relref . "/books/book-1" }} → /en/books/book-1/ |
| 33 |
|
| 34 |
{{ $opts := dict "path" "/books/book-1" }} |
| 35 |
{{ relref . $opts }} → /en/books/book-1/ |
| 36 |
|
| 37 |
{{ $opts := dict "path" "/books/book-1" "lang" "de" }} |
| 38 |
{{ relref . $opts }} → /de/books/book-1/ |
| 39 |
|
| 40 |
{{ $opts := dict "path" "/books/book-1" "lang" "de" "outputFormat" "json" }} |
| 41 |
{{ relref . $opts }} → /de/books/book-1/index.json |
| 42 |
``` |
| 43 |
|
| 44 |
## Error handling |
| 45 |
|
| 46 |
{{% include "_common/ref-and-relref-error-handling.md" %}} |