Debian Codegraph @

docs/content/en/functions/urls/Ref.md

raw
1 ---
2 title: urls.Ref
3 description: Returns the absolute URL of the page with the given path, language, and output format.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 aliases: [ref]
9 returnType: string
10 signatures:
11 - urls.Ref PAGE PATH
12 - urls.Ref PAGE OPTIONS
13 aliases: [/functions/ref]
14 ---
15
16 ## Usage
17
18 The `ref` 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 {{ ref . "/books/book-1" }} → https://example.org/en/books/book-1/
33
34 {{ $opts := dict "path" "/books/book-1" }}
35 {{ ref . $opts }} → https://example.org/en/books/book-1/
36
37 {{ $opts := dict "path" "/books/book-1" "lang" "de" }}
38 {{ ref . $opts }} → https://example.org/de/books/book-1/
39
40 {{ $opts := dict "path" "/books/book-1" "lang" "de" "outputFormat" "json" }}
41 {{ ref . $opts }} → https://example.org/de/books/book-1/index.json
42 ```
43
44 ## Error handling
45
46 {{% include "_common/ref-and-relref-error-handling.md" %}}