Hello!
i’m having a hard time figuring out what is causing some inconsistent behavior on my hugo site. I do not have a repository so I’ll try to be as descriptive as possible here.
my website has 3 categories of pages:
Blog
Galleries
Cameras
In the front matter of Galleries and Cameras, I have a custom parameter, “camera”
In the Cameras section, I’m calling a shortcode which will pull camera information out of a YAML file and display it in a list next to some pictures of the specific camera. At the end of the shortcode, I use that camera parameter to range through the galleries and show which were shot with that specific camera.
This functionality works like 10% of the time and I don’t know why.
camera/camera1/index.md
+++
title = "Olympus XA"
date = "2023-08-24T18:49:46.000Z"
draft = false
featured_image = "images/1.jpg"
summary = "the pocket rangefinder that could."
tags = ["camera"]
camera = "olympusxa"
+++
{{< camera_info data="camera1" cameraval="olympusxa" >}}
# Thoughts
Here are some random thoughts and reviews about this camera!
shortcodes/camera_info.html
{{ $caminfo := .Params.data }}
{{ $featimg := .Params.fi }}
{{ $cameraval := page.Param "camera" }}
{{ $cameraval }}
<div class="colrow">
<div class="column">
{{ range .Page.Resources }}
<img src="{{ .RelPermalink }}">
{{ end }}
</div>
<div class="column">
<ul>
<h3>Camera Information:</h3>
{{ $order := slice "maker" "model" "format" "style" "lens" }}
{{ $camera := index .Site.Data.cameralist.cameras $caminfo }}
{{ range $order }}
{{/* print all known fields in the desired order */}}
{{ $k := . }}
{{ $v := index $camera $k }}
{{ if eq $k "maker" }}
<li class="cameraList"><a href="/categories/{{ $v }}" class="listHead">{{ $k }}: {{ $v }}</a></li>
{{ else if eq $k "format"}}
<li class="cameraList"><a href="/categories/{{ $v }}" class="listHead">{{ $k }}: {{ $v }}</a></li>
{{ else if eq $k "style" }}
<li class="cameraList"><a href="/categories/{{ $v }}" class="listHead">{{ $k }}: {{ $v }}</a></li>
{{ else }}
<li class="cameraList">{{ $k }}: {{ $v }}</li>
{{ end }}
{{ end }}
{{ range $k, $v := $camera }}
{{ if not (in $order $k) }}
{{/* print remaining fields not contained in the desired order;
by that, additional fields unknown at the time of writing this
shortcode are still printed at the end of the list */}}
<li class="cameraList">{{ $k }}: {{ $v }}</li>
{{ end }}
{{ end }}
</ul>
</div>
</div>
{{ $events := where (where .Site.RegularPages "Section" "galleries") "Params.camera" "eq" $cameraval }}
{{ $events }}
{{ if len $events | eq 0 }}
<p>I have yet to develop any film from this camera!</p>
{{ else }}
<h3>
Sample Galleries
</h3>
{{ end }}
<p>
<ul>
{{ range where (where .Site.RegularPages "Section" "galleries") "Params.camera" "eq" $cameraval }}
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
{{ end }}
</ul>
</p>
At the beginning of this HTML file you can see that I call $cameraval
just to see if its populating and a lot of the time it isn’t. If i delete that line maybe it’ll start working again, if I add it or change something trivial again, maybe it’ll work again. Its extremely inconsistent. I WAS using SCRATCH to grab the front matter parameter and change dto a bespoke variable because I read that if scratch is being used by other partials it coudl cause problems so I just got that out of the way and the behavior is still the same.
Thanks for you help, let me know if you need any other information.