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.
{{% note %}}
See [this Go issue](https://github.com/golang/go/issues/10608) for the main motivation behind Scratch.
{{% /note %}}
`Scratch` is added to both `Page` and `Shortcode` -- with following methods:
*`Set` and `Add` takes a `key` and the `value` to add.
*`Get` returns the `value` for the `key` given.
*`SetInMap` takes a `key`, `mapKey` and `value`
*`GetSortedMapValues` returns array of values from `key` sorted by `mapKey`
`Set` and `SetInMap` can store values of any type.
For single values, `Add` accepts values that support Go's `+` operator. If the first `Add` for a key is an array or slice, the following adds will be appended to that list.
The scope of the backing data is global for the given `Page` or `Shortcode`, and spans partial and shortcode includes.
Note that `.Scratch` from a shortcode will return the shortcode's `Scratch`, which in most cases is what you want. If you want to store it in the page scroped Scratch, then use `.Page.Scratch`.
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" }}`.