.Scratch.Get: wrong number of args for Get: want 1 get 0

I copied a code from a tutorial which gives me an error:

{{ .Scratch.Add "greetings" (slice "Hello") }}
{{ .Scratch.Add "greetings" (slice "Goodbye") }}
{{ .Scratch.Add "greetings" (slice "Aloha" "Buenos dias") }}
{{ range where .Scratch.Get "greetings" }}
<ol>
	<li>
		{{ . }}
	</li>
</ol>
{{ end }}

Error: <.Scratch.Get>: wrong number of args for Get: want 1 got 0

Debugging 1

{{ .Scratch.Add "greetings" (slice "Hello") }}
{{ .Scratch.Add "greetings" (slice "Goodbye") }}
{{ .Scratch.Add "greetings" (slice "Aloha" "Buenos dias") }}
{{ .Scratch.Get "greetings" }}

prints

[Hello Goodbye Aloha Buenos dias]

Debugging 2

{{ .Scratch.Add "greetings" (slice "Hello") }}
{{ .Scratch.Add "greetings" (slice "Goodbye") }}
{{ .Scratch.Add "greetings" (slice "Aloha" "Buenos dias") }}
{{ range .Scratch.Get "greetings" }}
<ol>
	<li>
		{{ . }}
	</li>
</ol>
{{ end }}

…which prints the correct output. So the tutorial is wrong?

Yes, this line is incorrect:

{{ range where .Scratch.Get "greetings" }}

cc @regis

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.