In a go template, I'd like to get the last message in a loop, to be used outside the loop:
{{range $m := .messages}}
<div>Message subject: {{$m.Subject}}</div>
{{$lastMsg := $m}}
{{end}}
<div>The last message's subject: {{$lasMsg.Subject}}</div>
But this does not work and I get this error:
undefined variable "$lastMsg"
I have also tried {{.lastMsg := $m}}
but then I get:
unexpected ":=" in operand
So how can I fix this?