mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
Scratch doc: Use the special $ variable to prevent confusion
This commit is contained in:
parent
13d9009406
commit
dd9344816a
1 changed files with 12 additions and 10 deletions
|
@ -25,18 +25,20 @@ The scope of the backing data is global for the given `Node` or `Page`, and span
|
|||
The usage is best illustrated with some samples:
|
||||
|
||||
```
|
||||
{{ .Scratch.Add "a1" 12 }}
|
||||
{{ .Scratch.Get "a1" }} {{/* => 12 */}}
|
||||
{{ .Scratch.Add "a1" 1 }}
|
||||
{{ .Scratch.Get "a1" }} // {{/* => 13 */}}
|
||||
{{ $.Scratch.Add "a1" 12 }}
|
||||
{{ $.Scratch.Get "a1" }} {{/* => 12 */}}
|
||||
{{ $.Scratch.Add "a1" 1 }}
|
||||
{{ $.Scratch.Get "a1" }} // {{/* => 13 */}}
|
||||
|
||||
{{ .Scratch.Add "a2" "AB" }}
|
||||
{{ .Scratch.Get "a2" }} {{/* => AB */}}
|
||||
{{ .Scratch.Add "a2" "CD" }}
|
||||
{{ .Scratch.Get "a2" }} {{/* => ABCD */}}
|
||||
{{ $.Scratch.Add "a2" "AB" }}
|
||||
{{ $.Scratch.Get "a2" }} {{/* => AB */}}
|
||||
{{ $.Scratch.Add "a2" "CD" }}
|
||||
{{ $.Scratch.Get "a2" }} {{/* => ABCD */}}
|
||||
|
||||
{{ .Scratch.Set "v1" 123 }}
|
||||
{{ .Scratch.Get "v1" }} {{/* => 123 */}}
|
||||
{{ $.Scratch.Set "v1" 123 }}
|
||||
{{ $.Scratch.Get "v1" }} {{/* => 123 */}}
|
||||
```
|
||||
|
||||
**Note:** The examples above uses the special `$` variable, which refers to the top-level node. This is the behavior you most likely want, and will help remove some confusion when using `Scratch` inside page range loops -- and you start inadvertently calling the wrong `Scratch`. But there may be use cases for `{{ .Scratch.Add "key" "some value" }}`.
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue