A way to have some pages from a section to be in section of its own?

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.

No need to have a fourth section. Just use Hugo’s taxonomies

1 Like

But taxonomies don’t get top-level directories in the rendered site the way sections do, do they?

If this is just a matter of URL management…

content/
├── cars/
│   ├── cars-1.md
│   └── cars-2.md
├── electric-cars/
│   ├── electric-cars-1.md
│   └── electric-cars-2.md
└── _index.md

site configuration

# 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.

1 Like

I read your post again, and your goal may be different that what I described above; it’s a bit ambiguous.

site configuration

[[module.mounts]]
source = 'content'
target = 'content'

[[module.mounts]]
source = 'content/electric-cars'
target = 'content/cars'

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).

1 Like

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:

[[module.mounts]]
source = 'content'
target = 'content'

[[module.mounts]]
source = 'content/electric-cars'
target = 'content/cars'

[[module.mounts]]
source = 'content/cars'
target = 'content/cars'

Without that last mount, only electric-cars will render under public/cars.

I obtain the desired results with only the first two mounts.

 rm -rf public/ && hugo && tree public
public/
├── cars/
│   ├── cars-1/
│   │   └── index.html
│   ├── cars-2/
│   │   └── index.html
│   ├── electric-cars-1/
│   │   └── index.html
│   ├── electric-cars-2/
│   │   └── index.html
│   └── index.html
├── electric-cars/
│   ├── electric-cars-1/
│   │   └── index.html
│   ├── electric-cars-2/
│   │   └── index.html
│   └── index.html
└── index.html

Try it:

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
1 Like

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