I cannot get .HasChildren to work. I defined the parents and made references to identifiers. But has children returns nil every time. How to do iterate over parents (topic1, topic2) and then over their respective children?
What am I missing?
Thank you for a swift reply. I still don’t understand most of things.
I have read the two links you have provided. Heck, I’ve been reading Hugo documentation for the past four hours.
So in your case, it is looking at a HasChildren key in your section object, which is in a data file.
How do I make it have children? I want “q1” to be the child of “topic1”. I thought this works by assigning parent parameters, but it doesn’t. I just want to have a FAQ page with three sections, each of which has a list of Q&As.
I need to understand how to structure my page and I don’t think the documentation is all that clear on this topics.
In Hugo, “menus” mean something special. You define your menus either in your config.toml file, or on your content front matter. NOT in your /data/ folder. In Hugo menus, parent-child relationships are defined by specifying the "parent" value in the child entry.
The /data/ folder contains regular data files. These may be toml, yaml, or json format files. Here, parent-child relationships are typically implied in their structures;
title = "This is a parent"
title = "This is child 1"
title = "This is child 2"
You can of course still define the relationships by setting the parent value in the children, but it gets more complicated to parse then. You can read about how to iterate over data like this in Hugo here: https://gohugo.io/templates/introduction/#logic