Hi there,
I’m new to Hugo, and I find that a major pain point of working with templates is the inability to assign values to existing variables. For example,
{{ $foo := "Hello" }}
{{ $foo = "world" }} // THIS DOESN'T WORK!
{{ $foo }}
does not work. However, I noticed the very handy Scratch function, which allows operations like this:
{{ $.Scratch.Add "foo" "Hello"}}
{{ $.Scratch.Set "foo" "world"}}
{{ $.Scratch.Get "foo" }} //Outputs "world"
However, I have a use case where I’d want to use the value of $foo in the Scratch scope. I’ve tried {{ $bar := $.Scratch.Get "foo"}}, but this doesn’t seem to be possible. Is there a way to extract the value of a Scratch variable? Or even better, a way to re-assign values to variables in the templates? Thank you.