How to capture variable from range

Hi! Im looking for a way to do something like this:

{{ $justTesting  := ""}}
{{ range first 1 .Site.Pages }}
   {{ $justTesting := .Params.customParam }}
{{ end }}
{{ $justTesting }}

Something similar to liquid’s capture.

Thanks for any help!

{{ $justTesting := (index $.Data.Pages 0).Params.customParam }}

While @jgreely is right, it won’t help with the actual question, “capture a variable from a range”. The only current way to set a variable inside a range and make it visible to the outside is to use Scratch. This is discussed in lengths other places and in the docs.

Got it! That’s what I need.

@jgreely that wasn’t exactly what I was looking for, but I also needed that. I’m just learning Hugo, and sometimes I get confused with the templating language. This piece of code you shared with me it’s also extremely helpful.