[Solved] Delimit outputting string of numbers

Can somebody please explain why I’m getting this result? Where are those numbers coming from?

{{ $.Scratch.Add "key" "value" }}
{{ $.Scratch.Get "key" }}
-> output: "value"

{{ delimit ($.Scratch.Get "key") ", " }}
-> output: "value 114, 101, 115, 117, 108, 116"

EDIT: Ah, I see it’s outputting the ASCII character positions for each character. I’m still confused as to why and to what use? Is this expected and proper behavior?

Using php explode on a string will list every letter in the string, I suppose Golang converts those characters into ASCII to better store them.

Now if you need to create a proper slice using .Scratch.Add, we improved the doc on this, go have a look: https://gohugo.io/functions/scratch#add

2 Likes

Thanks — I think if the results were individual letters it would tell me the typeof the Scratch, which would be handy. I think that’s what I would expect here.

There is no method to evaluate the type of the .Scratch (not that I know of anyway), but I can’t imagine a scenario where using a .Scratch unaware of its type :thinking: