mirror of
https://github.com/gohugoio/hugoDocs.git
synced 2025-09-14 18:07:51 -04:00
Clarify that "with" blocks do not render with empty values (#1287)
* Clarify that "with" blocks do not render on empty values * Fix typo
This commit is contained in:
parent
b48de8b0a2
commit
1de7a358ca
@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
title: with
|
title: with
|
||||||
# linktitle: with
|
# linktitle: with
|
||||||
description: Rebinds the context (`.`) within its scope and skips the block if the variable is absent.
|
description: Rebinds the context (`.`) within its scope and skips the block if the variable is absent or empty.
|
||||||
godocref:
|
godocref:
|
||||||
date: 2017-02-01
|
date: 2017-02-01
|
||||||
publishdate: 2017-02-01
|
publishdate: 2017-02-01
|
||||||
@ -18,7 +18,11 @@ relatedfuncs: []
|
|||||||
deprecated: false
|
deprecated: false
|
||||||
---
|
---
|
||||||
|
|
||||||
An alternative way of writing an `if` statement and then referencing the same value is to use `with` instead. `with` rebinds the context (`.`) within its scope and skips the block if the variable is absent or unset.
|
An alternative way of writing an `if` statement and then referencing the same value is to use `with` instead. `with` rebinds the context (`.`) within its scope and skips the block if the variable is absent, unset or empty.
|
||||||
|
|
||||||
|
The set of *empty* values is defined by [the Go templates package](https://golang.org/pkg/text/template/). Empty values include `false`, the number zero, and the empty string.
|
||||||
|
|
||||||
|
If you want to render a block if an index or key is present in a slice, array, channel or map, regardless of whether the value is empty, you should use [`isset`](/functions/isset) instead.
|
||||||
|
|
||||||
The following example checks for a [user-defined site variable](/variables/site/) called `twitteruser`. If the key-value is not set, the following will render nothing:
|
The following example checks for a [user-defined site variable](/variables/site/) called `twitteruser`. If the key-value is not set, the following will render nothing:
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user