Respecting type and layout, again

Over the last couple of years a few different GitHub issues have been tracked relating to Hugo respecting explicit type and layout properties in page front matter.

I have encountered another issue of this kind and created a test case repo on GitHub. I’d like to know if anyone disagrees (or agrees) that this shows a bug in Hugo and should have an issue filed.

At https://github.com/crisperdue/hugo-test1 the file test.md has explicit type and layout, but is rendered using a default layout. If I remove the file
test/test2.md, then test.md is laid out according to its front matter, and
test3.md is laid out according to its explicit type and layout in both cases.

So I’m checking with the community before filing a bug report.

thanks,
Cris

1 Like

I suspect your problem is hidden by the symptoms.

If you’re running Hugo >= 0.55, try:

hugo --path-warnings

The problem is that you have both a section and a page that ends at the same URL.

2 Likes

Yes, that certainly seems to be the issue, thank you! When I turn on --path-warnings I get the message:

WARN 2019/05/29 08:45:35 Duplicate target paths: <repo>/public/test/index.html (2)

This is very helpful and important in my case. Perhaps it would be good for it to be turned on by default.

In my own head I have unpacked your response. Any experts please can you correct mistakes I may be making here. It appears to me that:

Hugo does not require an _index.md file to generate a list page. It will do so based on the existence of any content file in a subdirectory of content/. In fact it seems that only since version 0.18 has it been possible to affect the generation of “list pages” by creating an _index.md, and this goes with the slogan “everything is a page”.

Further experimentation seems to indicate that if I move the (content) file /test.md to /test/_index.md, Hugo does respect its type and layout, so I can have pretty URLs /test/ and /test/test2/, both with the layout I specify in front matter.

In the documentation I have not found an explicit statement that Hugo generates “section pages”, though at Lists of content in Hugo | Hugo it does say:

Since v0.18, everything in Hugo is a Page . This means list pages and the homepage can have associated content files (i.e. _index.md ) that contain page metadata (i.e., front matter) and content.

Fortunately for me, the additional statement just below:

It is important to note that all _index.md content files will render according to a list template and not according to a single page template.

This evidently is obsolete, and has changed with more recent work for Hugo to respect type and layout.

OK? Corrections?

1 Like

Yes, we recently (not sure when) added support for layout and type for _index.md type of pages, but the above statement is still correct in that the list type of pages have some different template lookups than the single pages (_default/list etc.)

2 Likes

OK, thanks again.