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/functions/go-template | |
parent | 208a0de6c31354df6f9463d49e90db9dec935169 (diff) | |
parent | 5be51ac3db225d5df501ed1fa1499c41d97dbf65 (diff) | |
download | hugo-653f1c1d462332bccf303a5040e5cd99c89a4378.tar.gz hugo-653f1c1d462332bccf303a5040e5cd99c89a4378.zip |
Merge commit '5be51ac3db225d5df501ed1fa1499c41d97dbf65'
Diffstat (limited to 'docs/content/en/functions/go-template')
21 files changed, 149 insertions, 245 deletions
diff --git a/docs/content/en/functions/go-template/_common/_index.md b/docs/content/en/functions/go-template/_common/_index.md deleted file mode 100644 index 4328d4d14..000000000 --- a/docs/content/en/functions/go-template/_common/_index.md +++ /dev/null @@ -1,13 +0,0 @@ ---- -cascade: - _build: - list: never - publishResources: false - render: never ---- - -<!-- -Files within this headless branch bundle are Markdown snippets. Each file must contain front matter delimiters, though front matter fields are not required. - -Include the rendered content using the "include" shortcode. ---> diff --git a/docs/content/en/functions/go-template/_common/text-template.md b/docs/content/en/functions/go-template/_common/text-template.md deleted file mode 100644 index 4b934c1e9..000000000 --- a/docs/content/en/functions/go-template/_common/text-template.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -_comment: Do not remove front matter. ---- - -See Go's [text/template] documentation for more information. - -[text/template]: https://pkg.go.dev/text/template diff --git a/docs/content/en/functions/go-template/_common/truthy-falsy.md b/docs/content/en/functions/go-template/_common/truthy-falsy.md deleted file mode 100644 index e15e58d61..000000000 --- a/docs/content/en/functions/go-template/_common/truthy-falsy.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -_comment: Do not remove front matter. ---- - -The falsy values are `false`, `0`, any `nil` pointer or interface value, any array, slice, map, or string of length zero, and zero `time.Time` values. - -Everything else is truthy. diff --git a/docs/content/en/functions/go-template/_index.md b/docs/content/en/functions/go-template/_index.md index 9075756aa..627dc2849 100644 --- a/docs/content/en/functions/go-template/_index.md +++ b/docs/content/en/functions/go-template/_index.md @@ -1,14 +1,7 @@ --- title: Go template functions, operators, and statements linkTitle: go template -description: Template functions, operators, and statements provided by Go's text/template package. +description: These are the functions, operators, and statements provided by Go's text/template package. categories: [] keywords: [] -menu: - docs: - parent: functions --- - -These are the functions, operators, and statements provided by Go's [text/template] package. - -[text/template]: https://pkg.go.dev/text/template diff --git a/docs/content/en/functions/go-template/and.md b/docs/content/en/functions/go-template/and.md index 6bc8c60a5..77906df52 100644 --- a/docs/content/en/functions/go-template/and.md +++ b/docs/content/en/functions/go-template/and.md @@ -3,16 +3,14 @@ title: and description: Returns the first falsy argument. If all arguments are truthy, returns the last argument. categories: [] keywords: [] -action: - aliases: [] - related: - - functions/go-template/not - - functions/go-template/or - returnType: any - signatures: [and VALUE...] +params: + functions_and_methods: + aliases: [] + returnType: any + signatures: [and VALUE...] --- -{{% include "functions/go-template/_common/truthy-falsy.md" %}} +{{% include "/_common/functions/truthy-falsy.md" %}} ```go-html-template {{ and 1 0 "" }} → 0 (int) @@ -22,5 +20,3 @@ action: {{ and "a" "b" "c" }} → c (string) {{ and "a" 1 true }} → true (bool) ``` - -{{% include "functions/go-template/_common/text-template.md" %}} diff --git a/docs/content/en/functions/go-template/block.md b/docs/content/en/functions/go-template/block.md index f8a082037..bffab1f8c 100644 --- a/docs/content/en/functions/go-template/block.md +++ b/docs/content/en/functions/go-template/block.md @@ -3,13 +3,11 @@ title: block description: Defines a template and executes it in place. categories: [] keywords: [] -action: - aliases: [] - related: - - functions/go-template/define - - functions/go-template/end - returnType: - signatures: [block NAME CONTEXT] +params: + functions_and_methods: + aliases: [] + returnType: + signatures: [block NAME CONTEXT] --- A block is shorthand for defining a template: @@ -25,7 +23,7 @@ and then executing it in place: ``` The typical use is to define a set of root templates that are then customized by redefining the block templates within. -{{< code file=layouts/_default/baseof.html >}} +```go-html-template {file="layouts/_default/baseof.html"} <body> <main> {{ block "main" . }} @@ -33,16 +31,16 @@ The typical use is to define a set of root templates that are then customized by {{ end }} </main> </body> -{{< /code >}} +``` -{{< code file=layouts/_default/single.html >}} +```go-html-template {file="layouts/_default/single.html"} {{ define "main" }} <h1>{{ .Title }}</h1> {{ .Content }} {{ end }} -{{< /code >}} +``` -{{< code file=layouts/_default/list.html >}} +```go-html-template {file="layouts/_default/list.html"} {{ define "main" }} <h1>{{ .Title }}</h1> {{ .Content }} @@ -50,6 +48,6 @@ The typical use is to define a set of root templates that are then customized by <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2> {{ end }} {{ end }} -{{< /code >}} +``` -{{% include "functions/go-template/_common/text-template.md" %}} +{{% include "/_common/functions/go-template/text-template.md" %}} diff --git a/docs/content/en/functions/go-template/break.md b/docs/content/en/functions/go-template/break.md index 14074d7c0..9236ec91e 100644 --- a/docs/content/en/functions/go-template/break.md +++ b/docs/content/en/functions/go-template/break.md @@ -3,13 +3,11 @@ title: break description: Used with the range statement, stops the innermost iteration and bypasses all remaining iterations. categories: [] keywords: [] -action: - aliases: [] - related: - - functions/go-template/continue - - functions/go-template/range - returnType: - signatures: [break] +params: + functions_and_methods: + aliases: [] + returnType: + signatures: [break] --- This template code: @@ -30,4 +28,4 @@ Is rendered to: <p>foo</p> ``` -{{% include "functions/go-template/_common/text-template.md" %}} +{{% include "/_common/functions/go-template/text-template.md" %}} diff --git a/docs/content/en/functions/go-template/continue.md b/docs/content/en/functions/go-template/continue.md index c8030b8b7..0b9339bf4 100644 --- a/docs/content/en/functions/go-template/continue.md +++ b/docs/content/en/functions/go-template/continue.md @@ -3,13 +3,11 @@ title: continue description: Used with the range statement, stops the innermost iteration and continues to the next iteration. categories: [] keywords: [] -action: - aliases: [] - related: - - functions/go-template/break - - functions/go-template/range - returnType: - signatures: [continue] +params: + functions_and_methods: + aliases: [] + returnType: + signatures: [continue] --- This template code: @@ -31,4 +29,4 @@ Is rendered to: <p>baz</p> ``` -{{% include "functions/go-template/_common/text-template.md" %}} +{{% include "/_common/functions/go-template/text-template.md" %}} diff --git a/docs/content/en/functions/go-template/define.md b/docs/content/en/functions/go-template/define.md index f15dd6ff0..19762a3d6 100644 --- a/docs/content/en/functions/go-template/define.md +++ b/docs/content/en/functions/go-template/define.md @@ -3,16 +3,11 @@ title: define description: Defines a template. categories: [] keywords: [] -action: - aliases: [] - related: - - functions/go-template/block - - functions/go-template/end - - functions/go-template/template - - functions/partials/Include - - functions/partials/IncludeCached - returnType: - signatures: [define NAME] +params: + functions_and_methods: + aliases: [] + returnType: + signatures: [define NAME] --- Use with the [`block`] statement: @@ -52,4 +47,4 @@ Use with the [`template`] function: [`template`]: /functions/go-template/block/ [`partial`]: /functions/partials/include/ -{{% include "functions/go-template/_common/text-template.md" %}} +{{% include "/_common/functions/go-template/text-template.md" %}} diff --git a/docs/content/en/functions/go-template/else.md b/docs/content/en/functions/go-template/else.md index 698998bd8..db3980070 100644 --- a/docs/content/en/functions/go-template/else.md +++ b/docs/content/en/functions/go-template/else.md @@ -3,15 +3,11 @@ title: else description: Begins an alternate block for if, with, and range statements. categories: [] keywords: [] -action: - aliases: [] - related: - - functions/go-template/if - - functions/go-template/range - - functions/go-template/with - - functions/go-template/end - returnType: - signatures: [else VALUE] +params: + functions_and_methods: + aliases: [] + returnType: + signatures: [else VALUE] --- Use with the [`if`] statement: @@ -62,7 +58,7 @@ Use `else if` to check multiple conditions. {{ end }} ``` -{{% include "functions/go-template/_common/text-template.md" %}} +{{% include "/_common/functions/go-template/text-template.md" %}} [`if`]: /functions/go-template/if/ [`with`]: /functions/go-template/with/ diff --git a/docs/content/en/functions/go-template/end.md b/docs/content/en/functions/go-template/end.md index 6fb5bbfd6..6de120724 100644 --- a/docs/content/en/functions/go-template/end.md +++ b/docs/content/en/functions/go-template/end.md @@ -3,16 +3,11 @@ title: end description: Terminates if, with, range, block, and define statements. categories: [] keywords: [] -action: - aliases: [] - related: - - functions/go-template/block - - functions/go-template/define - - functions/go-template/if - - functions/go-template/range - - functions/go-template/with - returnType: - signatures: [end] +params: + functions_and_methods: + aliases: [] + returnType: + signatures: [end] --- Use with the [`if`] statement: @@ -56,7 +51,7 @@ Use with the [`define`] statement: {{ end }} ``` -{{% include "functions/go-template/_common/text-template.md" %}} +{{% include "/_common/functions/go-template/text-template.md" %}} [`block`]: /functions/go-template/block/ [`define`]: /functions/go-template/define/ diff --git a/docs/content/en/functions/go-template/if.md b/docs/content/en/functions/go-template/if.md index 9fdf80e99..af2989cca 100644 --- a/docs/content/en/functions/go-template/if.md +++ b/docs/content/en/functions/go-template/if.md @@ -3,18 +3,14 @@ title: if description: Executes the block if the expression is truthy. categories: [] keywords: [] -action: - aliases: [] - related: - - functions/go-template/with - - functions/go-template/else - - functions/go-template/end - - functions/collections/IsSet - returnType: - signatures: [if EXPR] +params: + functions_and_methods: + aliases: [] + returnType: + signatures: [if EXPR] --- -{{% include "functions/go-template/_common/truthy-falsy.md" %}} +{{% include "/_common/functions/truthy-falsy.md" %}} ```go-html-template {{ $var := "foo" }} @@ -49,6 +45,6 @@ Use `else if` to check multiple conditions: {{ end }} ``` -{{% include "functions/go-template/_common/text-template.md" %}} +{{% include "/_common/functions/go-template/text-template.md" %}} [`else`]: /functions/go-template/else/ diff --git a/docs/content/en/functions/go-template/len.md b/docs/content/en/functions/go-template/len.md index 43f150a5f..6a13784e3 100644 --- a/docs/content/en/functions/go-template/len.md +++ b/docs/content/en/functions/go-template/len.md @@ -3,15 +3,11 @@ title: len description: Returns the length of a string, slice, map, or collection. categories: [] keywords: [] -action: - aliases: [] - related: - - functions/strings/Count - - functions/strings/CountRunes - - functions/strings/CountWords - - functions/strings/RuneCount - returnType: int - signatures: [len VALUE] +params: + functions_and_methods: + aliases: [] + returnType: int + signatures: [len VALUE] aliases: [/functions/len] --- @@ -48,4 +44,4 @@ You may also determine the number of pages in a collection with: {{ site.RegularPages.Len }} → 42 ``` -{{% include "functions/go-template/_common/text-template.md" %}} +{{% include "/_common/functions/go-template/text-template.md" %}} diff --git a/docs/content/en/functions/go-template/not.md b/docs/content/en/functions/go-template/not.md index 4c7747c7b..fd8b9afae 100644 --- a/docs/content/en/functions/go-template/not.md +++ b/docs/content/en/functions/go-template/not.md @@ -3,13 +3,11 @@ title: not description: Returns the boolean negation of its single argument. categories: [] keywords: [] -action: - aliases: [] - related: - - functions/go-template/and - - functions/go-template/or - returnType: bool - signatures: [not VALUE] +params: + functions_and_methods: + aliases: [] + returnType: bool + signatures: [not VALUE] --- Unlike the `and` and `or` operators, the `not` operator always returns a boolean value. @@ -32,4 +30,4 @@ Use the `not` operator, twice in succession, to cast any value to a boolean valu {{ "" | not | not }} → false ``` -{{% include "functions/go-template/_common/text-template.md" %}} +{{% include "/_common/functions/go-template/text-template.md" %}} diff --git a/docs/content/en/functions/go-template/or.md b/docs/content/en/functions/go-template/or.md index 0d8619608..2f55fe479 100644 --- a/docs/content/en/functions/go-template/or.md +++ b/docs/content/en/functions/go-template/or.md @@ -3,16 +3,14 @@ title: or description: Returns the first truthy argument. If all arguments are falsy, returns the last argument. categories: [] keywords: [] -action: - aliases: [] - related: - - functions/go-template/and - - functions/go-template/not - returnType: any - signatures: [or VALUE...] +params: + functions_and_methods: + aliases: [] + returnType: any + signatures: [or VALUE...] --- -{{% include "functions/go-template/_common/truthy-falsy.md" %}} +{{% include "/_common/functions/truthy-falsy.md" %}} ```go-html-template {{ or 0 1 2 }} → 1 @@ -23,4 +21,4 @@ action: {{ or 0 "" false }} → false ``` -{{% include "functions/go-template/_common/text-template.md" %}} +{{% include "/_common/functions/go-template/text-template.md" %}} diff --git a/docs/content/en/functions/go-template/range.md b/docs/content/en/functions/go-template/range.md index 96713c4b7..a06907c79 100644 --- a/docs/content/en/functions/go-template/range.md +++ b/docs/content/en/functions/go-template/range.md @@ -3,20 +3,15 @@ title: range description: Iterates over a non-empty collection, binds context (the dot) to successive elements, and executes the block. categories: [] keywords: [] -action: - aliases: [] - related: - - functions/go-template/break - - functions/go-template/continue - - functions/go-template/else - - functions/go-template/end - returnType: - signatures: [range COLLECTION] +params: + functions_and_methods: + aliases: [] + returnType: + signatures: [range COLLECTION] aliases: [/functions/range] -toc: true --- -{{% include "functions/go-template/_common/truthy-falsy.md" %}} +{{% include "/_common/functions/truthy-falsy.md" %}} ```go-html-template {{ $s := slice "foo" "bar" "baz" }} @@ -59,9 +54,8 @@ Hugo will throw an error: The error occurs because we are trying to use the `.Title` method on an integer instead of a `Page` object. Within the `range` block, if we want to render the page title, we need to get the context passed into the template. -{{% note %}} -Use the `$` to get the context passed into the template. -{{% /note %}} +> [!note] +> Use the `$` to get the context passed into the template. This template will render the page title three times: @@ -71,11 +65,8 @@ This template will render the page title three times: {{ end }} ``` -{{% note %}} -Gaining a thorough understanding of context is critical for anyone writing template code. -{{% /note %}} - -[`seq`]: /functions/collections/seq/ +> [!note] +> Gaining a thorough understanding of context is critical for anyone writing template code. ## Array or slice of scalars @@ -191,8 +182,9 @@ Is rendered to: Unlike ranging over an array or slice, Hugo sorts by key when ranging over a map. -{{% include "functions/go-template/_common/text-template.md" %}} +{{% include "/_common/functions/go-template/text-template.md" %}} -[`else`]: /functions/go-template/else/ [`break`]: /functions/go-template/break/ [`continue`]: /functions/go-template/continue/ +[`else`]: /functions/go-template/else/ +[`seq`]: /functions/collections/seq/ diff --git a/docs/content/en/functions/go-template/return.md b/docs/content/en/functions/go-template/return.md index df5b2496e..eb6ba30cd 100644 --- a/docs/content/en/functions/go-template/return.md +++ b/docs/content/en/functions/go-template/return.md @@ -3,14 +3,11 @@ title: return description: Used within partial templates, terminates template execution and returns the given value, if any. categories: [] keywords: [] -action: - aliases: [] - related: - - functions/partials/Include - - functions/partials/IncludeCached - returnType: any - signatures: ['return [VALUE]'] -toc: true +params: + functions_and_methods: + aliases: [] + returnType: any + signatures: ['return [VALUE]'] --- The `return` statement is a non-standard extension to Go's [text/template package]. Used within partial templates, the `return` statement terminates template execution and returns the given value, if any. @@ -19,21 +16,20 @@ The returned value may be of any data type including, but not limited to, [`bool A `return` statement without a value returns an empty string of type `template.HTML`. -{{% note %}} -Unlike `return` statements in other languages, Hugo executes the first occurrence of the `return` statement regardless of its position within logical blocks. See [usage](#usage) notes below. -{{% /note %}} +> [!note] +> Unlike `return` statements in other languages, Hugo executes the first occurrence of the `return` statement regardless of its position within logical blocks. See [usage](#usage) notes below. ## Example By way of example, let's create a partial template that _renders_ HTML, describing whether the given number is odd or even: -{{< code file="layouts/partials/odd-or-even.html" >}} +```go-html-template {file="layouts/partials/odd-or-even.html"} {{ if math.ModBool . 2 }} <p>{{ . }} is even</p> {{ else }} <p>{{ . }} is odd</p> {{ end }} -{{< /code >}} +``` When called, the partial renders HTML: @@ -43,9 +39,9 @@ When called, the partial renders HTML: Instead of rendering HTML, let's create a partial that _returns_ a boolean value, reporting whether the given number is even: -{{< code file="layouts/partials/is-even.html" >}} +```go-html-template {file="layouts/partials/is-even.html"} {{ return math.ModBool . 2 }} -{{< /code >}} +``` With this template: @@ -66,19 +62,16 @@ Hugo renders: See additional examples in the [partial templates] section. -[partial templates]: /templates/partial/#returning-a-value-from-a-partial - ## Usage -{{% note %}} -Unlike `return` statements in other languages, Hugo executes the first occurrence of the `return` statement regardless of its position within logical blocks. -{{% /note %}} +> [!note] +> Unlike `return` statements in other languages, Hugo executes the first occurrence of the `return` statement regardless of its position within logical blocks. A partial that returns a value must contain only one `return` statement, placed at the end of the template. For example: -{{< code file="layouts/partials/is-even.html" >}} +```go-html-template {file="layouts/partials/is-even.html"} {{ $result := false }} {{ if math.ModBool . 2 }} {{ $result = "even" }} @@ -86,16 +79,18 @@ For example: {{ $result = "odd" }} {{ end }} {{ return $result }} -{{< /code >}} +``` -{{% note %}} -The construct below is incorrect; it contains more than one `return` statement. -{{% /note %}} +> [!note] +> The construct below is incorrect; it contains more than one `return` statement. -{{< code file="layouts/partials/do-not-do-this.html" >}} +```go-html-template {file="layouts/partials/do-not-do-this.html"} {{ if math.ModBool . 2 }} {{ return "even" }} {{ else }} {{ return "odd" }} {{ end }} -{{< /code >}} +``` + +[partial templates]: /templates/partial/#returning-a-value-from-a-partial +[text/template package]: https://pkg.go.dev/text/template diff --git a/docs/content/en/functions/go-template/template.md b/docs/content/en/functions/go-template/template.md index 0a72acdaa..dac1fa3be 100644 --- a/docs/content/en/functions/go-template/template.md +++ b/docs/content/en/functions/go-template/template.md @@ -3,14 +3,11 @@ title: template description: Executes the given template, optionally passing context. categories: [] keywords: [] -action: - aliases: [] - related: - - functions/go-template/define - - functions/partials/Include - - functions/partials/IncludeCached - returnType: - signatures: ['template NAME [CONTEXT]'] +params: + functions_and_methods: + aliases: [] + returnType: + signatures: ['template NAME [CONTEXT]'] --- Use the `template` function to execute [embedded templates]. For example: @@ -42,7 +39,7 @@ The example above can be rewritten using an [inline partial] template: {{ end }} ``` -{{% include "functions/go-template/_common/text-template.md" %}} +{{% include "/_common/functions/go-template/text-template.md" %}} [`partial`]: /functions/partials/include/ [inline partial]: /templates/partial/#inline-partials diff --git a/docs/content/en/functions/go-template/try.md b/docs/content/en/functions/go-template/try.md index f3385a04c..6aef4da36 100644 --- a/docs/content/en/functions/go-template/try.md +++ b/docs/content/en/functions/go-template/try.md @@ -3,29 +3,28 @@ title: try description: Returns a TryValue object after evaluating the given expression. categories: [] keywords: [] -action: - aliases: [] - related: [] - returnType: TryValue - signatures: ['try EXPRESSION'] -toc: true +params: + functions_and_methods: + aliases: [] + returnType: TryValue + signatures: ['try EXPRESSION'] --- {{< new-in 0.141.0 />}} The `try` statement is a non-standard extension to Go's [text/template] package. It introduces a mechanism for handling errors within templates, mimicking the `try-catch` constructs found in other programming languages. -[text/template]: https://pkg.go.dev/text/template - ## Methods The `TryValue` object encapsulates the result of evaluating the expression, and provides two methods: -Err -: (`string`) Returns a string representation of the error thrown by the expression, if an error occurred, or returns `nil` if the expression evaluated without errors. +### Err + +(`string`) Returns a string representation of the error thrown by the expression, if an error occurred, or returns `nil` if the expression evaluated without errors. -Value -: (`any`) Returns the result of the expression if the evaluation was successful, or returns `nil` if an error occurred while evaluating the expression. +### Value + +(`any`) Returns the result of the expression if the evaluation was successful, or returns `nil` if an error occurred while evaluating the expression. ## Explanation @@ -88,8 +87,6 @@ Hugo renders the above to: Error handling is essential when using the [`resources.GetRemote`] function to capture remote resources such as data or images. When calling this function, if the HTTP request fails, Hugo will fail the build. -[`resources.GetRemote`]: /functions/resources/getremote/ - Instead of failing the build, we can catch the error and emit a warning: ```go-html-template @@ -106,8 +103,9 @@ Instead of failing the build, we can catch the error and emit a warning: ``` In the above, note that the [context](g) within the last conditional block is the `TryValue` object returned by the `try` statement. At this point neither the `Err` nor `Value` methods returned anything, so the current context is not useful. Use the `$` to access the [template context] if needed. -[template context]: /templates/introduction/#template-context +> [!note] +> Hugo does not classify an HTTP response with status code 404 as an error. In this case `resources.GetRemote` returns nil. -{{% note %}} -Hugo does not classify an HTTP response with status code 404 as an error. In this case `resources.GetRemote` returns nil. -{{% /note %}} +[`resources.GetRemote`]: /functions/resources/getremote/ +[template context]: /templates/introduction/#template-context +[text/template]: https://pkg.go.dev/text/template diff --git a/docs/content/en/functions/go-template/urlquery.md b/docs/content/en/functions/go-template/urlquery.md index 946828f56..dc97f867e 100644 --- a/docs/content/en/functions/go-template/urlquery.md +++ b/docs/content/en/functions/go-template/urlquery.md @@ -3,12 +3,11 @@ title: urlquery description: Returns the escaped value of the textual representation of its arguments in a form suitable for embedding in a URL query. categories: [] keywords: [] -action: - aliases: [] - related: - - functions/collections/Querify - returnType: string - signatures: ['urlquery VALUE [VALUE...]'] +params: + functions_and_methods: + aliases: [] + returnType: string + signatures: ['urlquery VALUE [VALUE...]'] aliases: [/functions/urlquery] --- @@ -25,4 +24,4 @@ Is rendered to: <a href="https://example.org?url=https%3A%2F%2Fexample.com">Link</a> ``` -{{% include "functions/go-template/_common/text-template.md" %}} +{{% include "/_common/functions/go-template/text-template.md" %}} diff --git a/docs/content/en/functions/go-template/with.md b/docs/content/en/functions/go-template/with.md index a730f4d2c..c25ce3fba 100644 --- a/docs/content/en/functions/go-template/with.md +++ b/docs/content/en/functions/go-template/with.md @@ -3,20 +3,15 @@ title: with description: Binds context (the dot) to the expression and executes the block if expression is truthy. categories: [] keywords: [] -action: - aliases: [] - related: - - functions/go-template/if - - functions/go-template/else - - functions/go-template/end - - functions/collections/IsSet - returnType: - signatures: [with EXPR] +params: + functions_and_methods: + aliases: [] + returnType: + signatures: [with EXPR] aliases: [/functions/with] -toc: true --- -{{% include "functions/go-template/_common/truthy-falsy.md" %}} +{{% include "/_common/functions/truthy-falsy.md" %}} ```go-html-template {{ $var := "foo" }} @@ -78,9 +73,8 @@ Hugo will throw an error: The error occurs because we are trying to use the `.Title` method on an integer instead of a `Page` object. Inside of the `with` block, if we want to render the page title, we need to get the context passed into the template. -{{% note %}} -Use the `$` to get the context passed into the template. -{{% /note %}} +> [!note] +> Use the `$` to get the context passed into the template. This template will render the page title as desired: @@ -90,10 +84,9 @@ This template will render the page title as desired: {{ end }} ``` -{{% note %}} -Gaining a thorough understanding of context is critical for anyone writing template code. -{{% /note %}} +> [!note] +> Gaining a thorough understanding of context is critical for anyone writing template code. -{{% include "functions/go-template/_common/text-template.md" %}} +{{% include "/_common/functions/go-template/text-template.md" %}} [`else`]: /functions/go-template/else/ |