I apologize if this has been covered before, but I can’t seem to find a simple example of this anywhere.
I have a multi-level content structure. So nested sections within a section. How can I make a list template that merges .Sections with .Pages to display a list for my list template?
{{ range .Sections }}
<li class="list list--bare">
<a href="{{ .RelPermalink }}"><h2>{{ .Title }}</h2></a>
</li>
{{ end }}
{{ range .Pages }}
<li class="list list--bare">
<a href="{{ .RelPermalink }}"><h2>{{ .Title }}</h2></a>
</li>
{{ end }}
Your content section sub-structures do NOT define the output file structure. You define the structure in your config file under [permalinks]. Hugo does not have cascading sections.
I think you answered a different question than @jkinley asked. But I am curious to know which question you were trying to answer. In any case, it’s not as simple as you say.
By default content section sub-structures DO define the output file structure. Permlink config allows you to override it. I’m not sure what you mean by “Hugo does not have cascading sections”? That it doesn’t do it automatically beyond level 1? Yes. And no: If I have the following in my content dir, a section will be generated at every node:
/africa/kenya/nairobi/kibera/_index.md
But it won’t if I have:
/africa/kenya/nairobi/kibera/index.md
Hugo has a lot of surprising and inconsistent behavior that makes it very un-user-friendly. but that’s another topic.
@jkinley, I don’t know how to do what you ask off the top of my head since I don’t write templates much, but you need to create a slice value, append both the .Section and .Pages slices to it, sort it as you want, and then range over it as you are doing for the separate slices. (I hate the fact that I am saying “slice” instead of “list”; that one has to understand Go to code templates seems wrong; but I think topics on the forum use “slice” so you’ll find more answers that way)
Vassudanagunta, thanks! I totally agree with you on a lot of your points. That being said, I really do love Hugo. That being said, it seems silly that Hugo would not be able to do what I mentioned above.
Before agreeing with disparaging comments that do not respect the forum’s Community Guidelines let me just tell you that we are a group of volunteers and we like to help people, but note that our time is also limited.
By following the Requesting Help guidelines t is always faster to get meaningful help rather than posting code.
If you can please share a sample repo with the structure of your project and explain to me clearly what exactly you are trying to achieve.
i.e. Do you need to create lists of pages per Nested Section or something else?
This will make debugging easier. Also note the Hugo has the union and intersect functions that may assist you in rendering lists.
In my mind, there have been no disparaging comments made by Vassudanagunta in any way. Nor did anyone violate the Community Guidelines.
If you are referring to “surprising and inconsistent behavior that makes it very un-user-friendly” I don’t think that’s exactly inaccurate. And Vassudanagunta is free to share his opinion. He didn’t attack anyone or call anyone names. He was reaching out and trying to HELP me.
You can find many, many articles online that warn that Hugo can have a steep learning curve. And it does. That’s why we should be working together to help each other understand so that the next people coming on board have an easier time.
And, by the way, I am one of the volunteers working together to make Hugo great. And I think that Vassudanagunta likely feels the same way.
If you read the link that I posted the guidelines mention explicitly that the discussion here needs to be kept civil.
Said comment violates those guidelines in my book. And I am very lenient.
Also I see that you have not replied to any of the points I raised regarding your support ticket. Nor have you shared a link with the source code of your project as requested.