Single template for all content

Hello,

I struggle with how Hugo selects templates to render content. What I want is to use one template to render both “single” and “list” content (i.e. _index.md files). Is that possible with Hugo?

To provide an example - suppose my content looks like this:
content/projects/_index.md content/projects/project1.md
and I want to use one template for both of those files.

But whatever I do Hugo tries to use _default/list.html for _index.md and _default/single.html for project1.html.

I tried to use index.md instead but that led to some weird behaviour if I had more files in the content directory (the result differed from build to build even without changes in source, which - if I understood correctly this issue - is a result of parallel rendering).

Thanks for any help

Why do you want that, other than the expected DRY (don’t repeat yourself) argument?

I don’t really have a reason beside the DRY principle. I mean if I want the content rendered in the samy way, it doesn’t make sense to have two exactly identical templates. Of course I understand why it works like this and I agree that the automatic lists for sections are pretty nifty

What I’m trying to say is that we could probably append single.html to the lookup path for the list type of pages, but we should think careful about not adding more confusion in other areas …

I am not sure that is a good idea. Even though it would solve this particular issue for me it could get confusing very quickly. Once you decide you do want list.html for some sections it gets used for every _index.md anyway. And then you’re again in similar situation - you need 3 templates instead of 2: single.html, list.html and section.html (for cutomizing the “single” _index.md).

I think this would be better solved on my side by using partials. I will make a basic.html partial that renders whole page and include it from both single.html and list.html. This way I will have a few more files, but actual layout will be defined in single place.