List pages from given location in footer (cache/render order issue?)

I am getting started with Hugo and trying to get my way around and am currently stuck implementing a certain feature.

I am trying to port a larger site, but currently have only very minimal content moved over. Here’s what I have:

.
├── index.de.md
├── index.en.md
└── legal
    ├── credits
    │   ├── index.de.md
    │   └── index.en.md
    ├── datenschutz
    │   ├── index.de.md
    │   └── index.en.md
    ├── impressum
    │   ├── index.de.md
    │   └── index.en.md
    └── _index.md

I have a footer which I use on every page. I include it in my _default/baseof.html like this:

{{ partial "footer.html" . }}

Inside this footer I want to automatically list pages from certain areas. For now I want the links to the three legal pages there. Later on, I also need to to list all pages recursively from a different area (as a flat list). But I already have trouble with the first part.

Here is what I use in my partials/footer.html:

        <ul>
            {{ $legal := site.GetPage "/legal" }}
            {{ range $legal.RegularPagesRecursive }}
                <li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>
            {{ end }}
        </ul>

However this does not list anything when I’m on the homepage. When I am on the legal/impressum page it suddenly lists the impressum page! On the credits page it lists all three pages!

To me it suggests that Hugo is building the list of pages only while rendering the pages. When rendering the homepage it hasn’t seen the legal pages. When rendering the impressum, it has only seen that one, on the credit page it has seen them all.

Obviously that’s not what I want. I would have thought that Hugo would build a list of pages and it’s metadata before actually rendering the individual pages, but that seems not to be the case. Is there a way to enforce that? Is there a different way to achieve this kind of automatic listing?

With this content structure…

content/
├── legal/
│   ├── credits/
│   │   ├── index.de.md
│   │   └── index.en.md
│   ├── datenschutz/
│   │   ├── index.de.md
│   │   └── index.en.md
│   ├── impressum/
│   │   ├── index.de.md
│   │   └── index.en.md
│   ├── _index.de.md
│   └── _index.en.md
├── _index.de.md
└── _index.en.md

…I am unable to reproduce the problem as described:

git clone --single-branch -b hugo-forum-topic-49379 https://github.com/jmooring/hugo-testing hugo-forum-topic-49379
cd hugo-forum-topic-49379
hugo server

Tested with v0.125.1.

Huh. How odd. I can’t reproduce the problem with your checkout either. Now I need to figure out what’s different between your code and mine… Thanks for looking into it.

I can not figure it out. I change things here and there and it suddenly works, but then as soon as I restart the server it’s gone.

@jmooring would you mind having a quick look? I’m sure it must be something silly.

I don’t understand your “block” calls… at all. Legal is a list page, and should be rendered with list.html, which contains a “main” block that isn’t called from anywhere.

right, that block should be “content” - I updated it and also put a title in the frontmatter for legal. Still no change in the footer link behaviour.

Look at the file names in my example, specifically the names of the home page markdown files…

image

Now look at yours.

Ahhh! I knew it was something silly. Thank you very much for your help.

Next, I need to learn more about why Hugo differs between _index and index and why this would change the behaviour like that. But at least I now can continue to actually work on the site.

Thanks again!

https://gohugo.io/troubleshooting/faq/#what-is-the-difference-between-an-indexmd-file-and-an-_indexmd-file

Thanks, unfortunately it does not explain why Hugo differs between those. It seems a bit tedious to have to change my index to _index whenever I decide to add a deeper level into my page hierarchy…

Actually, it does explain it if you take the time to learn about branch vs leaf bundles.

https://gohugo.io/content-management/page-bundles/#comparison

image

Rereading this, I think I might understand where my confusion comes from…

Files with resource type page include content written in Markdown […] In a leaf bundle […] these files are only accessible as page resources. In a branch bundle, these files are only accessible as content pages.

If I understand this correctly, this is the main difference. And I think this is really only relevant when you have multiple pages in one directory. I come from a system where every page is it’s own folder, so there is not much difference to me between the two.

But I guess with my content tree, I could also have the following structure instead?

  • legal/impressum.de.md
  • legal/impressum.en.md
  • legal/credits.de.md
  • legal/credits.en.md
  • legal/datenschutz.en.md
  • legal/datenschutz.de.md
  • legal/index.de.md
  • legal/index.en.md

It’s still not 100% clear why it is technically necessary to use two different filenames here. But I guess it’s a performance optimization? When I see _index I do not need to do a full directory read to find any other pages?

The “main” difference is that leaf bundles have no descendants.

No. The “legal” page needs to have descendants, so you must have a branch bundle (_index.md).

To distinguish between bundle types.

Why? Wouldn’t it be the same as the “hugo-is-cool” bundle here?

Yeah sure. But I am wondering why it is necessary to differentiate. An index.html in a folder (in traditional webhosting) works the same whether there are other sub directories next to it or not. I am pretty sure there is a technical reason, but I am not getting it from the docs or your explanations.

PS: it might make sense if a mod could split off this discussion to a new thread.

I’m sorry I can’t make this any clearer. Perhaps somebody else can help.

Oh I just read:

These are resources of resource type page , accessible via the Resources method on the Page object. Hugo will not render these as individual pages.

So I misinterpreted what ressource type page means… so it’s either one folder per page or a folder with pages only but nothing else?

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.