diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2025-04-10 13:04:51 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2025-04-10 13:04:51 +0200 |
commit | 653f1c1d462332bccf303a5040e5cd99c89a4378 (patch) | |
tree | c993984f169a240567526e9993261241c0cda771 /docs/content/en/methods/shortcode | |
parent | 208a0de6c31354df6f9463d49e90db9dec935169 (diff) | |
parent | 5be51ac3db225d5df501ed1fa1499c41d97dbf65 (diff) | |
download | hugo-653f1c1d462332bccf303a5040e5cd99c89a4378.tar.gz hugo-653f1c1d462332bccf303a5040e5cd99c89a4378.zip |
Merge commit '5be51ac3db225d5df501ed1fa1499c41d97dbf65'
Diffstat (limited to 'docs/content/en/methods/shortcode')
-rw-r--r-- | docs/content/en/methods/shortcode/Get.md | 37 | ||||
-rw-r--r-- | docs/content/en/methods/shortcode/Inner.md | 64 | ||||
-rw-r--r-- | docs/content/en/methods/shortcode/InnerDeindent.md | 23 | ||||
-rw-r--r-- | docs/content/en/methods/shortcode/IsNamedParams.md | 17 | ||||
-rw-r--r-- | docs/content/en/methods/shortcode/Name.md | 14 | ||||
-rw-r--r-- | docs/content/en/methods/shortcode/Ordinal.md | 26 | ||||
-rw-r--r-- | docs/content/en/methods/shortcode/Page.md | 12 | ||||
-rw-r--r-- | docs/content/en/methods/shortcode/Params.md | 25 | ||||
-rw-r--r-- | docs/content/en/methods/shortcode/Parent.md | 22 | ||||
-rw-r--r-- | docs/content/en/methods/shortcode/Position.md | 21 | ||||
-rw-r--r-- | docs/content/en/methods/shortcode/Ref.md | 33 | ||||
-rw-r--r-- | docs/content/en/methods/shortcode/RelRef.md | 33 | ||||
-rw-r--r-- | docs/content/en/methods/shortcode/Scratch.md | 12 | ||||
-rw-r--r-- | docs/content/en/methods/shortcode/Site.md | 9 | ||||
-rw-r--r-- | docs/content/en/methods/shortcode/Store.md | 24 | ||||
-rw-r--r-- | docs/content/en/methods/shortcode/_index.md | 5 |
16 files changed, 163 insertions, 214 deletions
diff --git a/docs/content/en/methods/shortcode/Get.md b/docs/content/en/methods/shortcode/Get.md index 8874c7649..b9c01cfc4 100644 --- a/docs/content/en/methods/shortcode/Get.md +++ b/docs/content/en/methods/shortcode/Get.md @@ -3,49 +3,44 @@ title: Get description: Returns the value of the given argument. categories: [] keywords: [] -action: - related: - - methods/shortcode/IsNamedParams - - methods/shortcode/Params - returnType: any - signatures: [SHORTCODE.Get ARG] -toc: true +params: + functions_and_methods: + returnType: any + signatures: [SHORTCODE.Get ARG] --- Specify the argument by position or by name. When calling a shortcode within Markdown, use either positional or named argument, but not both. -{{% note %}} -Some shortcodes support positional arguments, some support named arguments, and others support both. Refer to the shortcode's documentation for usage details. -{{% /note %}} +> [!note] +> Some shortcodes support positional arguments, some support named arguments, and others support both. Refer to the shortcode's documentation for usage details. ## Positional arguments This shortcode call uses positional arguments: -{{< code file=content/about.md lang=md >}} +```text {file="content/about.md"} {{</* myshortcode "Hello" "world" */>}} -{{< /code >}} +``` To retrieve arguments by position: -{{< code file=layouts/shortcodes/myshortcode.html >}} +```go-html-template {file="layouts/shortcodes/myshortcode.html"} {{ printf "%s %s." (.Get 0) (.Get 1) }} → Hello world. -{{< /code >}} +``` ## Named arguments This shortcode call uses named arguments: -{{< code file=content/about.md lang=md >}} +```text {file="content/about.md"} {{</* myshortcode greeting="Hello" firstName="world" */>}} -{{< /code >}} +``` To retrieve arguments by name: -{{< code file=layouts/shortcodes/myshortcode.html >}} +```go-html-template {file="layouts/shortcodes/myshortcode.html"} {{ printf "%s %s." (.Get "greeting") (.Get "firstName") }} → Hello world. -{{< /code >}} +``` -{{% note %}} -Argument names are case-sensitive. -{{% /note %}} +> [!note] +> Argument names are case-sensitive. diff --git a/docs/content/en/methods/shortcode/Inner.md b/docs/content/en/methods/shortcode/Inner.md index ef8d05ecb..cdce4c1c3 100644 --- a/docs/content/en/methods/shortcode/Inner.md +++ b/docs/content/en/methods/shortcode/Inner.md @@ -3,28 +3,23 @@ title: Inner description: Returns the content between opening and closing shortcode tags, applicable when the shortcode call includes a closing tag. categories: [] keywords: [] -action: - related: - - functions/strings/Trim - - methods/page/RenderString - - functions/transform/Markdownify - - methods/shortcode/InnerDeindent - returnType: template.HTML - signatures: [SHORTCODE.Inner] -toc: true +params: + functions_and_methods: + returnType: template.HTML + signatures: [SHORTCODE.Inner] --- This content: -{{< code file=content/services.md lang=md >}} +```text {file="content/services.md"} {{</* card title="Product Design" */>}} We design the **best** widgets in the world. {{</* /card */>}} -{{< /code >}} +``` With this shortcode: -{{< code file=layouts/shortcodes/card.html >}} +```go-html-template {file="layouts/shortcodes/card.html"} <div class="card"> {{ with .Get "title" }} <div class="card-title">{{ . }}</div> @@ -33,7 +28,7 @@ With this shortcode: {{ .Inner | strings.TrimSpace }} </div> </div> -{{< /code >}} +``` Is rendered to: @@ -46,23 +41,17 @@ Is rendered to: </div> ``` -{{% note %}} -Content between opening and closing shortcode tags may include leading and/or trailing newlines, depending on placement within the Markdown. Use the [`strings.TrimSpace`] function as shown above to remove both carriage returns and newlines. - -[`strings.TrimSpace`]: /functions/strings/trimspace/ -{{% /note %}} +> [!note] +> Content between opening and closing shortcode tags may include leading and/or trailing newlines, depending on placement within the Markdown. Use the [`strings.TrimSpace`] function as shown above to remove carriage returns and newlines. -{{% note %}} -In the example above, the value returned by `Inner` is Markdown, but it was rendered as plain text. Use either of the following approaches to render Markdown to HTML. -{{% /note %}} +> [!note] +> In the example above, the value returned by `Inner` is Markdown, but it was rendered as plain text. Use either of the following approaches to render Markdown to HTML. ## Use RenderString Let's modify the example above to pass the value returned by `Inner` through the [`RenderString`] method on the `Page` object: -[`RenderString`]: /methods/page/renderstring/ - -{{< code file=layouts/shortcodes/card.html >}} +```go-html-template {file="layouts/shortcodes/card.html"} <div class="card"> {{ with .Get "title" }} <div class="card-title">{{ . }}</div> @@ -71,7 +60,7 @@ Let's modify the example above to pass the value returned by `Inner` through the {{ .Inner | strings.TrimSpace | .Page.RenderString }} </div> </div> -{{< /code >}} +``` Hugo renders this to: @@ -86,18 +75,15 @@ Hugo renders this to: You can use the [`markdownify`] function instead of the `RenderString` method, but the latter is more flexible. See [details]. -[details]: /methods/page/renderstring/ -[`markdownify`]: /functions/transform/markdownify/ - ## Alternative notation Instead of calling the shortcode with the `{{</* */>}}` notation, use the `{{%/* */%}}` notation: -{{< code file=content/services.md lang=md >}} +```text {file="content/services.md"} {{%/* card title="Product Design" */%}} We design the **best** widgets in the world. {{%/* /card */%}} -{{< /code >}} +``` When you use the `{{%/* */%}}` notation, Hugo renders the entire shortcode as Markdown, requiring the following changes. @@ -112,7 +98,7 @@ This configuration is not unsafe if _you_ control the content. Read more about H Second, because we are rendering the entire shortcode as Markdown, we must adhere to the rules governing [indentation] and inclusion of [raw HTML blocks] as provided in the [CommonMark] specification. -{{< code file=layouts/shortcodes/card.html >}} +```go-html-template {file="layouts/shortcodes/card.html"} <div class="card"> {{ with .Get "title" }} <div class="card-title">{{ . }}</div> @@ -122,7 +108,7 @@ Second, because we are rendering the entire shortcode as Markdown, we must adher {{ .Inner | strings.TrimSpace }} </div> </div> -{{< /code >}} +``` The difference between this and the previous example is subtle but required. Note the change in indentation, the addition of a blank line, and removal of the `RenderString` method. @@ -143,11 +129,15 @@ The difference between this and the previous example is subtle but required. Not </div> ``` -{{% note %}} -When using the `{{%/* */%}}` notation, do not pass the value returned by `Inner` through the `RenderString` method or the `markdownify` function. -{{% /note %}} +> [!note] +> Don't process the `Inner` value with `RenderString` or `markdownify` when using [Markdown notation] to call the shortcode. -[commonmark]: https://commonmark.org/ +[`markdownify`]: /functions/transform/markdownify/ +[`RenderString`]: /methods/page/renderstring/ +[`strings.TrimSpace`]: /functions/strings/trimspace/ +[CommonMark]: https://spec.commonmark.org/current/ +[details]: /methods/page/renderstring/ [indentation]: https://spec.commonmark.org/0.30/#indented-code-blocks -[raw html blocks]: https://spec.commonmark.org/0.30/#html-blocks +[Markdown notation]: /content-management/shortcodes/#notation +[raw HTML blocks]: https://spec.commonmark.org/0.31.2/#html-blocks [security model]: /about/security/ diff --git a/docs/content/en/methods/shortcode/InnerDeindent.md b/docs/content/en/methods/shortcode/InnerDeindent.md index ab4263709..0b8c8e2d8 100644 --- a/docs/content/en/methods/shortcode/InnerDeindent.md +++ b/docs/content/en/methods/shortcode/InnerDeindent.md @@ -1,13 +1,12 @@ --- title: InnerDeindent -description: Returns the content between opening and closing shortcode tags, with indentation removed, applicable when the shortcode call includes a closing tag. +description: Returns the content between opening and closing shortcode tags, with indentation removed, applicable when the shortcode call includes a closing tag. categories: [] keywords: [] -action: - related: - - methods/shortcode/Inner - returnType: template.HTML - signatures: [SHORTCODE.InnerDeindent] +params: + functions_and_methods: + returnType: template.HTML + signatures: [SHORTCODE.InnerDeindent] --- Similar to the [`Inner`] method, `InnerDeindent` returns the content between opening and closing shortcode tags. However, with `InnerDeindent`, indentation before the content is removed. @@ -16,7 +15,7 @@ This allows us to effectively bypass the rules governing [indentation] as provid Consider this Markdown, an unordered list with a small gallery of thumbnail images within each list item: -{{< code file=content/about.md lang=md >}} +```text {file="content/about.md"} - Gallery one {{</* gallery */>}} @@ -30,17 +29,17 @@ Consider this Markdown, an unordered list with a small gallery of thumbnail imag   {{</* /gallery */>}} -{{< /code >}} +``` In the example above, notice that the content between the opening and closing shortcode tags is indented by four spaces. Per the CommonMark specification, this is treated as an indented code block. With this shortcode, calling `Inner` instead of `InnerDeindent`: -{{< code file=layouts/shortcodes/gallery.html >}} +```go-html-template {file="layouts/shortcodes/gallery.html"} <div class="gallery"> {{ .Inner | strings.TrimSpace | .Page.RenderString }} </div> -{{< /code >}} +``` Hugo renders the Markdown to: @@ -67,11 +66,11 @@ Hugo renders the Markdown to: Although technically correct per the CommonMark specification, this is not what we want. If we remove the indentation using the `InnerDeindent` method: -{{< code file=layouts/shortcodes/gallery.html >}} +```go-html-template {file="layouts/shortcodes/gallery.html"} <div class="gallery"> {{ .InnerDeindent | strings.TrimSpace | .Page.RenderString }} </div> -{{< /code >}} +``` Hugo renders the Markdown to: diff --git a/docs/content/en/methods/shortcode/IsNamedParams.md b/docs/content/en/methods/shortcode/IsNamedParams.md index a1d93ddac..1e0a7f00e 100644 --- a/docs/content/en/methods/shortcode/IsNamedParams.md +++ b/docs/content/en/methods/shortcode/IsNamedParams.md @@ -3,28 +3,27 @@ title: IsNamedParams description: Reports whether the shortcode call uses named arguments. categories: [] keywords: [] -action: - related: - - methods/shortcode/Get - returnType: bool - signatures: [SHORTCODE.IsNamedParams] +params: + functions_and_methods: + returnType: bool + signatures: [SHORTCODE.IsNamedParams] --- To support both positional and named arguments when calling a shortcode, use the `IsNamedParams` method to determine how the shortcode was called. With this shortcode template: -{{< code file=layouts/shortcodes/myshortcode.html >}} +```go-html-template {file="layouts/shortcodes/myshortcode.html"} {{ if .IsNamedParams }} {{ printf "%s %s." (.Get "greeting") (.Get "firstName") }} {{ else }} {{ printf "%s %s." (.Get 0) (.Get 1) }} {{ end }} -{{< /code >}} +``` Both of these calls return the same value: -{{< code file=content/about.md lang=md >}} +```text {file="content/about.md"} {{</* myshortcode greeting="Hello" firstName="world" */>}} {{</* myshortcode "Hello" "world" */>}} -{{< /code >}} +``` diff --git a/docs/content/en/methods/shortcode/Name.md b/docs/content/en/methods/shortcode/Name.md index fcf92718f..b5f9b6c17 100644 --- a/docs/content/en/methods/shortcode/Name.md +++ b/docs/content/en/methods/shortcode/Name.md @@ -3,24 +3,22 @@ title: Name description: Returns the shortcode file name, excluding the file extension. categories: [] keywords: [] -action: - related: - - methods/shortcode/Position - - functions/fmt/Errorf - returnType: string - signatures: [SHORTCODE.Name] +params: + functions_and_methods: + returnType: string + signatures: [SHORTCODE.Name] --- The `Name` method is useful for error reporting. For example, if your shortcode requires a "greeting" argument: -{{< code file=layouts/shortcodes/myshortcode.html >}} +```go-html-template {file="layouts/shortcodes/myshortcode.html"} {{ $greeting := "" }} {{ with .Get "greeting" }} {{ $greeting = . }} {{ else }} {{ errorf "The %q shortcode requires a 'greeting' argument. See %s" .Name .Position }} {{ end }} -{{< /code >}} +``` In the absence of a "greeting" argument, Hugo will throw an error message and fail the build: diff --git a/docs/content/en/methods/shortcode/Ordinal.md b/docs/content/en/methods/shortcode/Ordinal.md index 41393fa22..def0c016f 100644 --- a/docs/content/en/methods/shortcode/Ordinal.md +++ b/docs/content/en/methods/shortcode/Ordinal.md @@ -3,29 +3,28 @@ title: Ordinal description: Returns the zero-based ordinal of the shortcode in relation to its parent. categories: [] keywords: [] -action: - related: [] - returnType: int - signatures: [SHORTCODE.Ordinal] +params: + functions_and_methods: + returnType: int + signatures: [SHORTCODE.Ordinal] --- The `Ordinal` method returns the zero-based ordinal of the shortcode in relation to its parent. If the parent is the page itself, the ordinal represents the position of this shortcode in the page content. -{{% note %}} -Hugo increments the ordinal with each shortcode call, regardless of the specific shortcode type. This means that the ordinal value is tracked sequentially across all shortcodes within a given page. -{{% /note %}} +> [!note] +> Hugo increments the ordinal with each shortcode call, regardless of the specific shortcode type. This means that the ordinal value is tracked sequentially across all shortcodes within a given page. This method is useful for, among other things, assigning unique element IDs when a shortcode is called two or more times from the same page. For example: -{{< code file=content/about.md lang=md >}} +```text {file="content/about.md"} {{</* img src="images/a.jpg" */>}} {{</* img src="images/b.jpg" */>}} -{{< /code >}} +``` This shortcode performs error checking, then renders an HTML `img` element with a unique `id` attribute: -{{< code file=layouts/shortcodes/img.html >}} +```go-html-template {file="layouts/shortcodes/img.html"} {{ $src := "" }} {{ with .Get "src" }} {{ $src = . }} @@ -38,7 +37,7 @@ This shortcode performs error checking, then renders an HTML `img` element with {{ else }} {{ errorf "The %q shortcode requires a 'src' argument. See %s" .Name .Position }} {{ end }} -{{< /code >}} +``` Hugo renders the page to: @@ -47,8 +46,7 @@ Hugo renders the page to: <img id="img-001" src="/images/b.jpg" width="600" height="400" alt=""> ``` -{{% note %}} -In the shortcode template above, the [`with`] statement is used to create conditional blocks. Remember that the `with` statement binds context (the dot) to its expression. Inside of a `with` block, preface shortcode method calls with a `$` to access the top level context passed into the template. +> [!note] +> In the shortcode template above, the [`with`] statement is used to create conditional blocks. Remember that the `with` statement binds context (the dot) to its expression. Inside of a `with` block, preface shortcode method calls with a `$` to access the top-level context passed into the template. [`with`]: /functions/go-template/with/ -{{% /note %}} diff --git a/docs/content/en/methods/shortcode/Page.md b/docs/content/en/methods/shortcode/Page.md index 8bb58fa18..774caf9fc 100644 --- a/docs/content/en/methods/shortcode/Page.md +++ b/docs/content/en/methods/shortcode/Page.md @@ -3,10 +3,10 @@ title: Page description: Returns the Page object from which the shortcode was called. categories: [] keywords: [] -action: - related: [] - returnType: hugolib.pageForShortcode - signatures: [SHORTCODE.Page] +params: + functions_and_methods: + returnType: hugolib.pageForShortcode + signatures: [SHORTCODE.Page] --- With this content: @@ -26,11 +26,11 @@ Calling this shortcode: We can access the front matter values using the `Page` method: -{{< code file=layouts/shortcodes/book-details.html >}} +```go-html-template {file="layouts/shortcodes/book-details.html"} <ul> <li>Title: {{ .Page.Title }}</li> <li>Author: {{ .Page.Params.author }}</li> <li>Published: {{ .Page.Params.publication_year }}</li> <li>ISBN: {{ .Page.Params.isbn }}</li> </ul> -{{< /code >}} +``` diff --git a/docs/content/en/methods/shortcode/Params.md b/docs/content/en/methods/shortcode/Params.md index c0772e36a..f001e737f 100644 --- a/docs/content/en/methods/shortcode/Params.md +++ b/docs/content/en/methods/shortcode/Params.md @@ -3,31 +3,30 @@ title: Params description: Returns a collection of the shortcode arguments. categories: [] keywords: [] -action: - related: - - methods/shortcode/Get - returnType: any - signatures: [SHORTCODE.Params] +params: + functions_and_methods: + returnType: any + signatures: [SHORTCODE.Params] --- When you call a shortcode using positional arguments, the `Params` method returns a slice. -{{< code file=content/about.md lang=md >}} +```text {file="content/about.md"} {{</* myshortcode "Hello" "world" */>}} -{{< /code >}} +``` -{{< code file=layouts/shortcodes/myshortcode.html >}} +```go-html-template {file="layouts/shortcodes/myshortcode.html"} {{ index .Params 0 }} → Hello {{ index .Params 1 }} → world -{{< /code >}} +``` When you call a shortcode using named arguments, the `Params` method returns a map. -{{< code file=content/about.md lang=md >}} +```text {file="content/about.md"} {{</* myshortcode greeting="Hello" name="world" */>}} -{{< /code >}} +``` -{{< code file=layouts/shortcodes/myshortcode.html >}} +```go-html-template {file="layouts/shortcodes/myshortcode.html"} {{ .Params.greeting }} → Hello {{ .Params.name }} → world -{{< /code >}} +``` diff --git a/docs/content/en/methods/shortcode/Parent.md b/docs/content/en/methods/shortcode/Parent.md index 740b1ad7e..91c445d2a 100644 --- a/docs/content/en/methods/shortcode/Parent.md +++ b/docs/content/en/methods/shortcode/Parent.md @@ -1,31 +1,31 @@ --- title: Parent -description: Returns the parent shortcode context in nested shortcodes. +description: Returns the parent shortcode context in nested shortcodes. categories: [] keywords: [] -action: - related: [] - returnType: hugolib.ShortcodeWithPage - signatures: [SHORTCODE.Parent] +params: + functions_and_methods: + returnType: hugolib.ShortcodeWithPage + signatures: [SHORTCODE.Parent] --- This is useful for inheritance of common shortcode arguments from the root. In this contrived example, the "greeting" shortcode is the parent, and the "now" shortcode is child. -{{< code file=content/welcome.md lang=md >}} +```text {file="content/welcome.md"} {{</* greeting dateFormat="Jan 2, 2006" */>}} Welcome. Today is {{</* now */>}}. {{</* /greeting */>}} -{{< /code >}} +``` -{{< code file=layouts/shortcodes/greeting.html >}} +```go-html-template {file="layouts/shortcodes/greeting.html"} <div class="greeting"> {{ .Inner | strings.TrimSpace | .Page.RenderString }} </div> -{{< /code >}} +``` -{{< code file=layouts/shortcodes/now.html >}} +```go-html-template {file="layouts/shortcodes/now.html"} {{- $dateFormat := "January 2, 2006 15:04:05" }} {{- with .Params }} @@ -41,7 +41,7 @@ Welcome. Today is {{</* now */>}}. {{- end }} {{- now | time.Format $dateFormat -}} -{{< /code >}} +``` The "now" shortcode formats the current time using: diff --git a/docs/content/en/methods/shortcode/Position.md b/docs/content/en/methods/shortcode/Position.md index 6f047c01b..24810e825 100644 --- a/docs/content/en/methods/shortcode/Position.md +++ b/docs/content/en/methods/shortcode/Position.md @@ -1,26 +1,24 @@ --- title: Position -description: Returns the filename and position from which the shortcode was called. +description: Returns the file name and position from which the shortcode was called. categories: [] keywords: [] -action: - related: - - methods/shortcode/Name - - functions/fmt/Errorf - returnType: text.Position - signatures: [SHORTCODE.Position] +params: + functions_and_methods: + returnType: text.Position + signatures: [SHORTCODE.Position] --- The `Position` method is useful for error reporting. For example, if your shortcode requires a "greeting" argument: -{{< code file=layouts/shortcodes/myshortcode.html >}} +```go-html-template {file="layouts/shortcodes/myshortcode.html"} {{ $greeting := "" }} {{ with .Get "greeting" }} {{ $greeting = . }} {{ else }} {{ errorf "The %q shortcode requires a 'greeting' argument. See %s" .Name .Position }} {{ end }} -{{< /code >}} +``` In the absence of a "greeting" argument, Hugo will throw an error message and fail the build: @@ -28,6 +26,5 @@ In the absence of a "greeting" argument, Hugo will throw an error message and fa ERROR The "myshortcode" shortcode requires a 'greeting' argument. See "/home/user/project/content/about.md:11:1" ``` -{{% note %}} -The position can be expensive to calculate. Limit its use to error reporting. -{{% /note %}} +> [!note] +> The position can be expensive to calculate. Limit its use to error reporting. diff --git a/docs/content/en/methods/shortcode/Ref.md b/docs/content/en/methods/shortcode/Ref.md index 305e1e7d8..3a877d568 100644 --- a/docs/content/en/methods/shortcode/Ref.md +++ b/docs/content/en/methods/shortcode/Ref.md @@ -3,27 +3,23 @@ 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] +params: + functions_and_methods: + returnType: string + signatures: [SHORTCODE.Ref OPTIONS] --- -The map of option contains: +## Usage -path -: (`string`) The path to the page, relative to the `content` directory. Required. +The `Ref` method accepts a single argument: an options map. -lang -: (`string`) The language (site) to search for the page. Default is the current language. Optional. +## Options -outputFormat -: (`string`) The output format to search for the page. Default is the current output format. Optional. +{{% include "_common/ref-and-relref-options.md" %}} -The examples below show the rendered output when visiting a page on the English language version of the site: +## Examples + +The following examples show the rendered output for a page on the English version of the site: ```go-html-template {{ $opts := dict "path" "/books/book-1" }} @@ -36,9 +32,6 @@ The examples below show the rendered output when visiting a page on the English {{ .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. +## Error handling -{{< code-toggle file=hugo >}} -refLinksErrorLevel = 'warning' -refLinksNotFoundURL = '/some/other/url' -{{< /code-toggle >}} +{{% include "_common/ref-and-relref-error-handling.md" %}} diff --git a/docs/content/en/methods/shortcode/RelRef.md b/docs/content/en/methods/shortcode/RelRef.md index 4e367312b..273705a95 100644 --- a/docs/content/en/methods/shortcode/RelRef.md +++ b/docs/content/en/methods/shortcode/RelRef.md @@ -3,27 +3,23 @@ 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] +params: + functions_and_methods: + returnType: string + signatures: [SHORTCODE.RelRef OPTIONS] --- -The map of option contains: +## Usage -path -: (`string`) The path to the page, relative to the `content` directory. Required. +The `RelRef` method accepts a single argument: an options map. -lang -: (`string`) The language (site) to search for the page. Default is the current language. Optional. +## Options -outputFormat -: (`string`) The output format to search for the page. Default is the current output format. Optional. +{{% include "_common/ref-and-relref-options.md" %}} -The examples below show the rendered output when visiting a page on the English language version of the site: +## Examples + +The following examples show the rendered output for a page on the English version of the site: ```go-html-template {{ $opts := dict "path" "/books/book-1" }} @@ -36,9 +32,6 @@ The examples below show the rendered output when visiting a page on the English {{ .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. +## Error handling -{{< code-toggle file=hugo >}} -refLinksErrorLevel = 'warning' -refLinksNotFoundURL = '/some/other/url' -{{< /code-toggle >}} +{{% include "_common/ref-and-relref-error-handling.md" %}} diff --git a/docs/content/en/methods/shortcode/Scratch.md b/docs/content/en/methods/shortcode/Scratch.md index 6dd882e24..6efec2097 100644 --- a/docs/content/en/methods/shortcode/Scratch.md +++ b/docs/content/en/methods/shortcode/Scratch.md @@ -3,14 +3,14 @@ title: Scratch description: Returns a "scratch pad" to store and manipulate data, scoped to the current shortcode. categories: [] keywords: [] -action: - related: [] - returnType: maps.Scratch - signatures: [SHORTCODE.Scratch] +params: + functions_and_methods: + returnType: maps.Scratch + signatures: [SHORTCODE.Scratch] expiryDate: 2026-11-18 # deprecated 2024-11-18 (soft) --- -{{% deprecated-in 0.139.0 %}} +{{< deprecated-in 0.139.0 >}} Use the [`SHORTCODE.Store`] method instead. This is a soft deprecation. This method will be removed in a future release, but the removal date has not been established. Although Hugo will not emit a warning if you continue to use this method, you should begin using `SHORTCODE.Store` as soon as possible. @@ -18,4 +18,4 @@ This is a soft deprecation. This method will be removed in a future release, but Beginning with v0.139.0 the `SHORTCODE.Scratch` method is aliased to `SHORTCODE.Store`. [`SHORTCODE.Store`]: /methods/shortcode/store/ -{{% /deprecated-in %}} +{{< /deprecated-in >}} diff --git a/docs/content/en/methods/shortcode/Site.md b/docs/content/en/methods/shortcode/Site.md index af2a755ee..4c5a9a9b5 100644 --- a/docs/content/en/methods/shortcode/Site.md +++ b/docs/content/en/methods/shortcode/Site.md @@ -3,11 +3,10 @@ title: Site description: Returns the Site object. categories: [] keywords: [] -action: - related: - - methods/page/Sites - returnType: page.siteWrapper - signatures: [SHORTCODE.Site] +params: + functions_and_methods: + returnType: page.siteWrapper + signatures: [SHORTCODE.Site] --- See [Site methods]. diff --git a/docs/content/en/methods/shortcode/Store.md b/docs/content/en/methods/shortcode/Store.md index 8d9a8596b..76cb9237d 100644 --- a/docs/content/en/methods/shortcode/Store.md +++ b/docs/content/en/methods/shortcode/Store.md @@ -3,28 +3,22 @@ title: Store description: Returns a "scratch pad" to store and manipulate data, scoped to the current shortcode. categories: [] keywords: [] -action: - related: - - methods/page/Store - - methods/site/Store - - functions/hugo/Store - - functions/collections/NewScratch - returnType: maps.Scratch - signatures: [SHORTCODE.Store] -toc: true +params: + functions_and_methods: + returnType: maps.Scratch + signatures: [SHORTCODE.Store] --- {{< new-in 0.139.0 />}} Use the `Store` method to create a [scratch pad](g) to store and manipulate data, scoped to the current shortcode. To create a scratch pad with a different [scope](g), refer to the [scope](#scope) section below. -{{% note %}} -With the introduction of the [`newScratch`] function, and the ability to [assign values to template variables] after initialization, the `Store` method within a shortcode is mostly obsolete. - -[assign values to template variables]: https://go.dev/doc/go1.11#text/template -[`newScratch`]: /functions/collections/newScratch/ -{{% /note %}} +> [!note] +> With the introduction of the [`newScratch`] function, and the ability to [assign values to template variables] after initialization, the `Store` method within a shortcode is mostly obsolete. {{% include "_common/store-methods.md" %}} {{% include "_common/scratch-pad-scope.md" %}} + +[`newScratch`]: /functions/collections/newScratch/ +[assign values to template variables]: https://go.dev/doc/go1.11#texttemplatepkgtexttemplate diff --git a/docs/content/en/methods/shortcode/_index.md b/docs/content/en/methods/shortcode/_index.md index 1c99adba7..0064f42aa 100644 --- a/docs/content/en/methods/shortcode/_index.md +++ b/docs/content/en/methods/shortcode/_index.md @@ -4,10 +4,5 @@ linkTitle: Shortcode description: Use these methods in your shortcode templates. categories: [] keywords: [] -menu: - docs: - parent: methods aliases: [/variables/shortcodes] --- - -Use these methods in your shortcode templates. |