Change COLLECTION in range based on page kind

How do I go about changing the collection within a range based on the page type? I’ve tried using scratch but I can never seem to get the scratch syntax to work. I’m still trying to wrap by head around how variables work within scopes for Hugo. Any help would be appreciated, I’ve tried some other methods on the forms but cant seems to figure it out. Thank you

{{if eq .Kind "home"}}
  {{$collection := .Site.Pages}}
{{else}}
  {{$collection := .Pages}}
{{end}}

{{range $collection}}

{{end}}

Initialize ( := ) outside the block, and assign ( = ) within.

{{ $var := 0 }}
{{ if true }}
  {{ $var = 1 }}
{{ else }}
  {{ $var = 2 }}
{{ end }}
1 Like