Oh, that’s interesting. I read Content Section vs Content Type and Assign a Content Type and thought that anything that ends up as something in a section (content/cats/_index.md, content/cats/index.md, content/cats.md, content/cats/siamese.md) automatically has a section of cats unless explicitly overridden. At the very least, I’d expect layouts/section/asdf.html to apply to content/asdf/index.md and content/asdf/_index.md. I put {{ define "content" }}asdfasdfa{{ end }} in it and never saw asdfasdfa show up on http://localhost:1313/asdf/.
Offhand I’m not sure how to rewrite the relevant bits of documentation so others don’t get confused the same way I was, but I’d very, very much appreciate more clarity from this in the official documentation. As far as I can tell staring at Examples: Layout Lookup for Section Pages, my setup should have worked.
I don’t understand why I have to put the type: asdf bit in the front matter for content/asdf.md when ‘Section list for “posts” section with type set to “blog”’ in Examples: Layout Lookup for Section Pages seems to suggest that I can put an overriding template in layouts/asdf/single.html and have that template redefine “content” or “endofmain”, but it doesn’t seem to work like that.
I suspect the documentation doesn’t match what Hugo does anymore.
While I deeply appreciate your willingness to help me figure out where to place my layouts, I don’t think I’m communicating my underlying problem well enough. What’s bothering me is that I read the docs and yet still came to incorrect conclusions about where I could put a template-layout file that would apply to a given .md file. As someone who likes Hugo and wants others’ Hugo use to be as painless as possible, it bothers me that reading the docs does not appear to be enough to understand where to put template-layout files.
Now, I will be the first person to admit that i sometimes skim documentation all too quickly and miss key bits of information, but after reading the doc pages linked to from my initial post, I’m beginning to think that the documentation isn’t communicating all aspects of the template-layout selection algorithm. As such, I’d like to use this thread to brainstorm ideas to more clearly communicate this very important part of Hugo to new(ish) users.
Of course, I’d be more than happy to contribute doc patches myself once I understand how it all works in all cases, but I’m clearly not there yet.
Is value of type if set in front matter, else it is the name of the root section (e.g. “blog”). It will always have a value, so if not set, the value is “page”.
content/asdf.md is not under a subdir under content, so unless set, type will be page.
And yet, content/asdf.md gets turned into /asdf/index.html, just as content/asdf/index.md or content/asdf/_index.md do (I can’t find where in the docs it says this happens, but it happens).
Because the generated index.html is in the asdf directory, I figure it has a section of asdf, and therefore layouts/section/asdf.html should apply to it, just like how layouts/section/posts.html is said to apply to “a section list for ‘posts’ section with type set to ‘blog’” in Examples: Layout Lookup for Section Pages.
In retrospect, “I don’t understand why I have to put the type: asdf bit…” is misleading when trying to communicate the main source of my confusion. I should have written “I don’t understand why I have to either move files around or add a type: asdf to make this work” or left that part out entirely.
A Section is a collection of pages that gets defined based on the organization structure under the content/ directory.
By default, all the first-level directories under content/ form their own sections (root sections).
Whether a page is a section or a regular page depends on the structure in your content, not the generated output. As in my example above, setting uglyURLs = true shows that content/foo.md will be generated at example.com/foo.html: just under the root.
Expanding further:
A page’s type is determined by default by the Section that contains it.
foo.md is a top-level content page; it is not a directory; it is not contained by a sub-directory under content;
Therefore it is not a Section, it is not in a Section;
Therefore foo.md will get the default type value “page”–
Thanks for explaining. Unfortunately, I’m getting mixed signals from Hugo itself for vaguely similar pages:
content/asdf.md has a section of <nil> and a type of page, as you said.
No surprises here.
content/aoeu/index.mdalso has a section of <nil> and a type of page.
This isn’t what I’d expect given that I’m accessing it as /aoeu/ and index.md is in the aoeu/ directory.
content/underscore-ijkl/_index.md straight-up 404s, which is a complete surprise to me. public/underscore-ijkl/ just doesn’t get generated.
content/underscore-zxcv-and-friend/_index.md, accessed through /underscore-zxcv-and-friend/, also doesn’t get generated.
Also, the built-in Hugo browser generates a blank page for this (a 403 page?) instead of the usual 404 page, but that’s not at all important now.
content/underscore-zxcv-and-friend/friend.md, accessed through /underscore-zxcv-and-friend/friend/, has a section of and a type of underscore-zxcv-and-friend.
I’d expect a section of underscore-zxcv-and-friend and a type of page.
content/qwer/index.md, accessed through /qwer/, has a section of and a type of page (surprising section, unsurprising type)
content/qwer/roommate.md doesn’t generate anything that shows up in public/.
Are the .CurrentSection and .Type of all these pages exactly what all the knowledgable users expect? I feel like I’m one of a handful of users getting regularly surprised by how Hugo appears to do things differently than how I’d predict it to do them just by reading the docs.
Thanks a lot for your help. I think it mostly all makes sense now.
…well, that explains a lot of the trouble I’ve been having. I copied over a config.yaml from a site where disabling sections made sense and then relied on sections being there.
After reenabling sections I’m still a little confused by some of what I’m seeing. In particular, this paragraph from https://gohugo.io/content-management/sections/ seems like it’s been misleading me a lot:
By default, all the first-level directories under content/ form their own sections (root sections).
This seems to be true only if there’s a _index.something (with an underscore!) in the first-level directory under content/. If my new, current understanding is correct, wouldn’t it be clearer to say
By default, all the first-level directories under content/ that are branch bundles (i.e. have an _index.md in them) form their own sections (root sections).
Also, if the only way to disable this default behavior is to disable sections entirely, then the following should be even clearer still:
Unless explicitly disabled with disableKinds in the config file, all the first-level directories under content/ that are branch bundles (i.e. have an _index.md in them) form their own sections (root sections).
Are any of these proposed wording changes clearer and truer than what’s there currently? I’d be happy to send in a patch this weekend or shortly thereafter.