How to loop through all instances of a front matter variable in section pages and total the value of them?

Hello,

I have the following which doesn’t throw an error but unfortunately doesn’t work. It attempts to:

  • Loop through all the instances of a front matter variable
  • Cast it to float
  • Total all the values

I just can’t figure out how to do this in Go. Is there a += variable assignment mechanism?

{{ $currenttotal := 0 }}
{{ range where .Pages "Status" "eq" "completed" }}
{{ $durationvalue := (float .Params.duration) }}
{{ $currenttotal := (add $currenttotal $durationvalue) }}
{{ end }}
{{ $currenttotal }}

Solved it… remove colon from final assignment.

{{ $currenttotal := 0 }}
{{ range where .Pages “Status” “eq” “completed” }}
{{ $durationvalue := (float .Params.duration) }}
{{ $currenttotal = (add $currenttotal $durationvalue) }}
{{ end }}
{{ $currenttotal }}

1 Like