mirror of
				https://github.com/gohugoio/hugo.git
				synced 2024-05-11 05:54:58 +00:00 
			
		
		
		
	Scratch doc: Use the special $ variable to prevent confusion
This commit is contained in:
		@@ -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:
 | 
					The usage is best illustrated with some samples:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
{{ .Scratch.Add "a1" 12 }}
 | 
					{{ $.Scratch.Add "a1" 12 }}
 | 
				
			||||||
{{ .Scratch.Get "a1" }} {{/* => 12 */}}
 | 
					{{ $.Scratch.Get "a1" }} {{/* => 12 */}}
 | 
				
			||||||
{{ .Scratch.Add "a1" 1 }}
 | 
					{{ $.Scratch.Add "a1" 1 }}
 | 
				
			||||||
{{ .Scratch.Get "a1" }} // {{/* => 13 */}}
 | 
					{{ $.Scratch.Get "a1" }} // {{/* => 13 */}}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
{{ .Scratch.Add "a2" "AB" }}
 | 
					{{ $.Scratch.Add "a2" "AB" }}
 | 
				
			||||||
{{ .Scratch.Get "a2" }} {{/* => AB */}}
 | 
					{{ $.Scratch.Get "a2" }} {{/* => AB */}}
 | 
				
			||||||
{{ .Scratch.Add "a2" "CD" }}
 | 
					{{ $.Scratch.Add "a2" "CD" }}
 | 
				
			||||||
{{ .Scratch.Get "a2" }} {{/* => ABCD */}}
 | 
					{{ $.Scratch.Get "a2" }} {{/* => ABCD */}}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
{{ .Scratch.Set "v1" 123 }}
 | 
					{{ $.Scratch.Set "v1" 123 }}
 | 
				
			||||||
{{ .Scratch.Get "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" }}`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user