I have a collection of guestbook entries in yaml format from when I built my site with Jekyll. They’re contained in /data/fridge. I’m trying to display them on the guestbook page with the following code:
Welcome to the forum. I’ll give my educated guesses, cause your posted snippet on it’s own lacks information to pin that down exactly. see Requesting Help
involved templates:
baseof.html - pass the context (the DOT)
{{ block "main" . }}{{ end }}
your template: the snippet works if
it can be found by the lookup rules → actually executed
you pass the context (dot from above) which is referenced via $.Site
the data structure matches your loop logic /data/fridge.yaml should look like:
- message: Mess 1
name: Name 1
- message: Mess2
name: Name 2
Hints:
check the generated html pages in /public/... to see if anything is generated
use {{ warnf "hello" }} to debug (processing info in console)
if you can’t spot it → Show your code and Hugo version, env
p.s. consider this - not a cause for your problem right now
site.Data is deprecated since (v0.156.0) change $.Site.fridge to:
156+ : hugo.Data.fridge
older versons: i would use site.Data.fridge which eleminates context problems
Perhaps it’s an issue with my data structure, I have each guestbook entry as an individual file, named like note-[timestamp].yaml with contents like so:
I’ve also confirmed that I have the correct block code in my baseof.html and the code I posted above in the OP is in a layout file called fridge.html in the root of the layouts directory.
check the example in hugo.Data. you will need the two variable form of range to capture the individual files.
before as i said: check the real html output if anything of your template is in. It should at least contain:
if not fix that first. to get assistance there we would need the actual involved files. prepare a minimal example or share your repo. recoding what might be there is double work for us
Okay having checked the html output, it did not output the contents of fridge.html after all. I had to add layout: fridge to the fridge.md file and now everything is outputting as it should. I was under the impression that the page would automatically use the layout with the matching name. I guess I should read up more on the lookup rules. Thank you so much for your help.