From 539f8e3b5d1ebfc7b57ec42f979fc6989c6d625f Mon Sep 17 00:00:00 2001 From: Dave Henderson Date: Wed, 15 Jan 2020 10:57:28 -0500 Subject: Documenting the initial context ($) variable Signed-off-by: Dave Henderson --- docs/content/syntax.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'docs') diff --git a/docs/content/syntax.md b/docs/content/syntax.md index 9fe49b33..c7995217 100644 --- a/docs/content/syntax.md +++ b/docs/content/syntax.md @@ -253,6 +253,20 @@ the default context from data sources with the [`--context`/`c`](../usage/#conte flag. The special context item [`.Env`](#env) is available for referencing the system's environment variables. +_Note:_ The initial context (`.`) is always available as the variable `$`, +so the initial context is always available, even when shadowed with `range` +or `with` blocks: + +``` +$ echo '{"bar":"baz"}' | gomplate -c .=stdin:///in.json -i 'context is: {{ . }} +{{ with "foo" }}now context is {{ . }} +but the original context is still {{ $ }} +{{ end }}' +context is: map[bar:baz] +now context is foo +but the original context is still map[bar:baz] +``` + ## Nested templates Gomplate supports nested templates, using Go's `template` action. These can be -- cgit v1.2.3