8000 Add Ref, RelRef, and Site shortcode methods · gohugoio/hugoDocs@749bb37 · GitHub
[go: up one dir, main page]

Skip to content

Commit

Permalink
Add Ref, RelRef, and Site shortcode methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jmooring committed Nov 28, 2023
1 parent 994d437 commit 749bb37
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 0 deletions.
44 changes: 44 additions & 0 deletions content/en/methods/shortcode/Ref.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
title: Ref
description: Returns the absolute URL of the page with the given path, language, and output format.
categories: []
keywords: []
action:
related:
- methods/shortcode/RelRef
- functions/urls/RelRef
- functions/urls/Ref
returnType: string
signatures: [SHORTCODE.Ref OPTIONS]
---

The map of option contains:

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.

The examples below show the rendered output when visiting a page on the English language version of the site:

```go-html-template
{{ $opts := dict "path" "/books/book-1" }}
{{ .Ref $opts }} → https://example.org/en/books/book-1/
{{ $opts := dict "path" "/books/book-1" "lang" "de" }}
{{ .Ref $opts }} → https://example.org/de/books/book-1/
{{ $opts := dict "path" "/books/book-1" "lang" "de" "outputFormat" "json" }}
{{ .Ref $opts }} → https://example.org/de/books/book-1/index.json
```

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.

{{< code-toggle file=hugo >}}
refLinksErrorLevel = 'warning'
refLinksNotFoundURL = '/some/other/url'
{{< /code-toggle >}}
44 changes: 44 additions & 0 deletions content/en/methods/shortcode/RelRef.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
title: RelRef
description: Returns the relative URL of the page with the given path, language, and output format.
categories: []
keywords: []
action:
related:
- methods/shortcode/Ref
- functions/urls/Ref
- functions/urls/RelRef
returnType: string
signatures: [SHORTCODE.RelRef OPTIONS]
---

The map of option contains:

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.

The examples below show the rendered output when visiting a page on the English language version of the site:

```go-html-template
{{ $opts := dict "path" "/books/book-1" }}
{{ .RelRef $opts }} → /en/books/book-1/
{{ $opts := dict "path" "/books/book-1" "lang" "de" }}
{{ .RelRef $opts }} → /de/books/book-1/
{{ $opts := dict "path" "/books/book-1" "lang" "de" "outputFormat" "json" }}
{{ .RelRef $opts }} → /de/books/book-1/index.json
```

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.

{{< code-toggle file=hugo >}}
refLinksErrorLevel = 'warning'
refLinksNotFoundURL = '/some/other/url'
{{< /code-toggle >}}
19 changes: 19 additions & 0 deletions content/en/methods/shortcode/Site.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
title: Site
description: Returns the Site object.
categories: []
keywords: []
action:
related:
- methods/page/Sites
returnType: page.siteWrapper
signatures: [SHORTCODE.Site]
---

See [Site methods].

[Site methods]: /methods/site

```go-html-template
{{ .Site.Title }}
```

0 comments on commit 749bb37

Please sign in to comment.
0