Merge commit '5be51ac3db225d5df501ed1fa1499c41d97dbf65'

This commit is contained in:
Bjørn Erik Pedersen
2025-04-10 13:04:51 +02:00
987 changed files with 12379 additions and 14083 deletions

View File

@@ -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/