From dd9344816a57586234e26554e06af331f16c0919 Mon Sep 17 00:00:00 2001 From: bep Date: Sun, 1 Feb 2015 20:36:43 +0100 Subject: [PATCH] Scratch doc: Use the special $ variable to prevent confusion --- docs/content/extras/scratch.md | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/docs/content/extras/scratch.md b/docs/content/extras/scratch.md index 9adef3a5a..578b1c354 100644 --- a/docs/content/extras/scratch.md +++ b/docs/content/extras/scratch.md @@ -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" }}`. +