Fitness and everything else

Changed My Weather Partials To Use Dict Instead Of Scratch

The idea of using Hugo’s dict to make a cleaner way to pass variables between partials. When I first converted my weather table generating short code to a partial, I split it up to make it a little easier to manage. Smaller files that do one thing instead of one large file that does it all. It’s just easier to edit and debug that way.

I noticed that I had a bug in it where one of the numbers wasn’t being passed correctly. When I first split the files up I had originally passed everything with Scratch which worked well enough at the time. I did want to convert it to a dict, so it’d be easier to read in a case like this. At that time, I wasn’t ready to tackle that yet, but I’d been looking at it for a few weeks. Last weekend was the time I finally decided to do it after working on something else in a related partial.

Now I just call the partial with

{{- partial "Wx/Pressure.gohtml" (dict "WxData" $WxData ) -}}

That passes all of my weather variables as WxData .

The partial that generates my table for the barometric pressure is

1{{- with .WxData -}}
2<table> <caption>Releative Pressure</caption> <thead><tr>
3<th></th><th>Pressure</th><th>Time</th> </tr> </thead>
5<tr><td>Average</td><td>{{ .AveragePressure -}} &#8243;</td><td></td></tr>
6<tr><td>High</td><td>{{ .HighPressure -}} &#8243;</td><td><time datetime="{{ .HighPressureTime }}"> {{- .HighPressureTime | time.Format ":time_short" -}}</time></td></tr>
7<tr><td>Low</td><td>{{ .LowPressure -}} &#8243;</td><td><time datetime="{{ .LowPressureTime }}"> {{- .LowPressureTime | time.Format ":time_short" -}}</time> </td></tr>
8<tr><td>Range</td><td>{{ .PressureRange -}} &#8243;</td><td></td></tr></tbody>
12{{- partialCached "top.gohtml" . -}}
13{{- end -}}