mirror of
				https://github.com/gohugoio/hugo.git
				synced 2025-11-04 04:27:46 -05:00 
			
		
		
		
	
							parent
							
								
									de8fc8761a
								
							
						
					
					
						commit
						048e07422d
					
				@ -14,8 +14,7 @@ weight: 80
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
`Scratch` -- a "scratchpad" for your node- or page-scoped variables. In most cases you can do well without `Scratch`, but there are some use cases that aren't solvable with Go's templates without `Scratch`'s help, due to scoping issues.
 | 
					`Scratch` -- a "scratchpad" for your node- or page-scoped variables. In most cases you can do well without `Scratch`, but there are some use cases that aren't solvable with Go's templates without `Scratch`'s help, due to scoping issues.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					`Scratch` is added to both `Node` and `Page` and `Shortcode` -- with following methods:
 | 
				
			||||||
`Scratch` is added to both `Node` and `Page` -- with following methods:
 | 
					 | 
				
			||||||
* `Set` and `Add` takes a `key` and the `value` to add.
 | 
					* `Set` and `Add` takes a `key` and the `value` to add.
 | 
				
			||||||
* `Get` returns the `value` for the `key` given.
 | 
					* `Get` returns the `value` for the `key` given.
 | 
				
			||||||
* `SetInMap` takes a `key`, `mapKey` and `value`
 | 
					* `SetInMap` takes a `key`, `mapKey` and `value`
 | 
				
			||||||
@ -25,7 +24,9 @@ weight: 80
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
For single values, `Add` accepts values that support Go's `+` operator. If the first `Add` for a key is an array or slice, the follwing adds will be appended to that list.
 | 
					For single values, `Add` accepts values that support Go's `+` operator. If the first `Add` for a key is an array or slice, the follwing adds will be appended to that list.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
The scope of the backing data is global for the given `Node` or `Page`, and spans partial and shortcode includes.
 | 
					The scope of the backing data is global for the given `Node`, `Page` or `Shortcode`, and spans partial and shortcode includes.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Note that `.Scratch` from a shortcode will return the shortcode's `Scratch`, which in most casses is what you want. If you want to store it in the page scroped Scratch, then use `.Page.Scratch`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Sample usage
 | 
					## Sample usage
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -36,6 +36,7 @@ type ShortcodeWithPage struct {
 | 
				
			|||||||
	Page          *Page
 | 
						Page          *Page
 | 
				
			||||||
	Parent        *ShortcodeWithPage
 | 
						Parent        *ShortcodeWithPage
 | 
				
			||||||
	IsNamedParams bool
 | 
						IsNamedParams bool
 | 
				
			||||||
 | 
						scratch       *Scratch
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (scp *ShortcodeWithPage) Site() *SiteInfo {
 | 
					func (scp *ShortcodeWithPage) Site() *SiteInfo {
 | 
				
			||||||
@ -51,7 +52,10 @@ func (scp *ShortcodeWithPage) RelRef(ref string) (string, error) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (scp *ShortcodeWithPage) Scratch() *Scratch {
 | 
					func (scp *ShortcodeWithPage) Scratch() *Scratch {
 | 
				
			||||||
	return scp.Page.Scratch()
 | 
						if scp.scratch == nil {
 | 
				
			||||||
 | 
							scp.scratch = newScratch()
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return scp.scratch
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (scp *ShortcodeWithPage) Get(key interface{}) interface{} {
 | 
					func (scp *ShortcodeWithPage) Get(key interface{}) interface{} {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user