Multiple layouts for same content

Hello awesome community!

I have a bunch of contents for a conference site, it’s organized like this:

content
├── _index.md
├── talks
│   ├── _index.md
│   ├── a-talk.md
│   ├── another-talk.md
│   ├── even-another-talk.md
│   └── yet-another-talk.md

I want to have several versions of each talk page, for instance:

website.com/talks/a-talk/
website.com/talks/a-talk/fancy-display/

So each talk page would have multiple layouts, using the same content.

Is this possible without doing copies of a-talk/index.md => a-talk/fancy-display.md with taxonomy modified (which I would have to do for each talk)? Is there a way to easily define that everything in content/talks/ should have multiple URLs with different layouts?

There are at least a couple of ways to do this. Here’s one that’s somewhat easy to wrap your head around…

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

structure

content
├── talks/
│   ├── talk-1/
│   │   ├── fancy.md 
│   │   └── _index.md  <-- this has the content
│   └── talk-2/
│       ├── fancy.md
│       └── _index.md  <-- this has the content
└── _index.md

templates

layouts/talks/
├── single-fancy.html
└── single.html

The trick is to set the layout value in front matter. Please clone the repository for details.

2 Likes

You might also consider an alternate output format for this content type. See:
https://discourse.gohugo.io/t/where-do-i-place-an-almost-static-html-file/37235/13

Thanks @jmooring for an inspirational answer – and in addition to that, templating your forum solutions with Github examples, it’s genius!

The solution seems to have an unquestionable “Hugo-way” about it, so I can guess it doesn’t get much better. It has the slight drawback that I have to create empty stubs for every instance of /talks/<some-talk>/fancy/. I think that I can live with that, but I was hoping that Hugo would have a way of populating several URLs with different templates of the same content.

I see now that what I am talking about would be some kind of non-existing new Template Views feature.

Thanks again!

You are welcome. The other approach that I mentioned does not require the “empty stubs.” It might be more to your liking.

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