How to disable section but use section url on menus and/or disable section only on sub-sections

Example 01

Disable sections via config but use section URL and .Section on menu (each doc page catch .Section and set active menu item via it)

/docs/overview      ← have url: "docs/overview", aliases: "/docs"
/docs/page2

When disable sections via hugo.yml, /docs URL not set on menu

menus:
  main:
    - identifier: home
      name: Home
      pageRef: /
      weight: 10
    - identifier: docs
      name: Documentation
      pageRef: /docs
      weight: 20
{{ $section := .Section }}
{{ $currentURL := .RelPermalink }}
{{ range $.Site.Menus.main }}
<option value="{{ .URL | absLangURL }}" {{ if or (eq $section .Identifier) (eq $currentURL .URL) -}}selected{{ end }}>
	<span aria-hidden="">{{.Pre}}</span>
	<span>{{ .Name }}</span>
</option>
{{ end }}

Example 02

Support section theme on root section but use list theme on subsections

/blogs                  ← root section/ section layout
/blogs/travel       ← non-root sections/ list layout
/blogs/programming    ← non-root sections/ list layout

I am building both in 1 theme.

I am not 100% sure I understand what you are asking, but we have build settings in frontmatter. You would need to add an explicit _index.md for each section and then you can use the frontmatter to define if they come up in list pages. Maybe reading through this docs page gets you further.

@davidsneighbour I’ve tried both ways for “Example 01”

  1. disableKinds: [section] on config
  2. _index.md

Without a layouts/section.html

---
build:
  list: never
  render: never
title: Documentation
---

For some reason in Hugo, when disable section in either way attached menu not get /docs path and it’s getting converts to /.

Not sure what you did, but nothing aligns with what the documentation says.

You need to add in content/section-you-want-to-hide/_index.md the following:

[build]
list = 'never'
render = 'always'

This influences the visibility and rendering of section-you-want-to-hide. I don’t know what the value of list should be for your case, because I only needed to hide the section from the site, but not the pages in it (which the above should do. The section is hidden on nav and /section-you-want-to-hide/somepage/ loads in the browser.

@davidsneighbour Sorry, typo(corrected). When disable sections on config or disable list on docs/_index.md, menu {{ .URL | absLangURL }} not get /docs as it’s getting convert to / instead, even on home page menu items.

build:
list: never

Example 01

if you disable the generation of a page, there is no page you can link to (the alias does not count)
docs/_index.html

+++
title = 'Docs'
[build]
list = 'never'
render = 'never'
+++

either directly link to the subpage

  [[menus.main]]
    name = 'Docs'
    pageRef = '/docs/overview'
    weight = 20

or use an URL

  [[menus.main]]
    name = 'Docs'
    url = '/docs/'
    weight = 20

which then redirects ro the page… maybe the first one is the better option

example 02:

you could set the layout explicit on the docs page and cascade adifferent layout to the child sections.

docs/index.html

+++
title = 'Docs'
date = 2023-01-01T08:30:00-07:00
draft = false

layout = "section"
[[cascade]]
   layout = "list"
+++

you may want to add a cascade.target to separate sections from pages.

p.s. list.htmland section.html are both in the lookup order, so having both may have some strange effects… I would choose a custom layout name for the subsections.

not in deep knowlede of the new system…so there might be a better way.