I’m sure this question has been raised, but I can’t seem to find it.
Let’s say I have a site with sections like “/boats”, “/planes”, and “/cars”. Some cars are electric, and I also want a fourth section “/electric-cars”. The single.html layouts would be, perhaps, a little bit different for “/cars” and “/electric-cars”, yet I want all the electric cars render under “/cars”, too, because they are cars, even if electric.
Of course, I don’t want to create duplicates of my content files in two directories, so all the electric cars page bundles will live in only one place (doesn’t really matter if it will be /content/cars or /content/electric-cars, as long as I don’t need to maintain a copy for each).
What is the best approach to achieve this? I basically want one section to be both a section of its own and merged into another one. Merging it into the list is easy, but I also want those pages rendered in that path, too.
# Change the URLs
[permalinks]
electric-cars = '/cars/:title/'
# Make it easy build page collections and use the same templates
[[cascade]]
type = 'cars'
[cascade._target]
kind = 'page'
path = '/electric-cars/**'
# Prevent building the electric-cars section page (to avoid orphaned list page)
[[cascade]]
[cascade._build]
list = 'never'
render = 'never'
[cascade._target]
kind = 'section'
path = '/electric-cars'
But, if it were me, I wouldn’t worry about the URLs. Instead, I would use Hugo’s taxonomy system. From a content modeling perspective that makes more sense. A car, regardless of characteristics, is still a car.
This will render cars and electric-cars under public/cars.
It will also render electric-cars under public/electric-cars (the same pages in two places).
I need to read up on the mounts, but if this indeed appends content/cars with /content/electric-cars instead of completely replacing (like a linux filesystem mount), this is quite an optimal solution.
Thank you, this is it. I’m just documenting here for anyone who stumbles upon this topic later, that for this to work as intended, the config needs to be:
git clone --single-branch -b hugo-forum-topic-41755 https://github.com/jmooring/hugo-testing hugo-forum-topic-41755
cd hugo-forum-topic-41755
hugo server