Conditionally hide section of site not working

I’m trying to follow the Example – conditionally hide section.

$ hugo version
hugo v0.146.5+extended+withdeploy darwin/arm64 BuildDate=2025-04-15T17:54:38Z VendorInfo=brew

An abstract version of my multilingual site:

content
├── _index.de.md
├── _index.en.md
├── _index.sv.md
├── internal
│   ├── _index.md
│   └── sections
│       ├── _index.md
│       ├── a.de.md
│       ├── a.en.md
│       ├── a.sv.md
│       ├── b.de.md
│       ├── b.en.md
│       ├── b.sv.md
│       ├── c.de.md
│       ├── c.en.md
│       └── c.sv.md
└── sub
    ├── _index.de.md
    ├── _index.en.md
    └── _index.sv.md

I want to hide anything under the internal branch but still be able to include pages from internal/sections in various templates, for example I’m successfully able to this when building a menu:

{{ range $i, $s := where .Site.RegularPages "Type" "internal" }}
   <a href="{{ relLangURL "/" }}#{{ .LinkTitle | anchorize  }}">{{ .LinkTitle }}</a>
{{ end }}

I also successfully do this to render all the pages under internal/sections from another template:

{{ range $i, $s := where .Site.RegularPages "Type" "internal" }}
  {{ partial "section.html" (dict "context" . "nr" $i) }}
{{ end }}

To hide the internal branch, both content/internal/_index.md and content/internal/sections/_index.md have the following content:

+++
title = "Internal"

[[cascade]]
  [cascade.build]
    list = 'never'
    render = 'never'
  [cascade.target]
    environment = 'production'
+++

Despite this, for the default language (sv) the internal branch gets published.

public/internal
├── index.html
├── index.xml
└── sections
    ├── a
    │   └── index.html
    ├── index.html
    ├── index.xml
    ├── b
    │   └── index.html
    └── c
        └── index.html

Likwise for the de and en.

public/de/internal
├── index.html
├── index.xml
└── sections
    ├── a
    │   └── index.html
    ├── b
    │   └── index.html
    └── c
        └── index.html

, and:

public/en/internal
├── index.html
├── index.xml
└── sections
    ├── a
    │   └── index.html
    ├── b
    │   └── index.html
    └── c
        └── index.html

What am I doing wrong?

I’m on hugo 147.8

With your setup (also in 146.5) the exclusion of the internal section for the default language works fine for me. Maybe some other config problem problem there.

regarding the other languages:

Your '/content/internal/_index.md` is for the SV language.

You could solve this by creating an _index.md for every language.

OR as it seems your exclude is not depending on a language, just move it to your sites config

hugo.toml.

this will exclude all pages and the section itself.

[[cascade]]
   [cascade.build]
      list   = 'never'
      render = 'never'
   [cascade.target]
      environment = 'production'
      path        = '{/internal,/internal/**}'

p.s. you don’t need to repeat the cascade in deeper _index files

p.p.s. tested with 145,0, too and there cascade in frontmatter only works for current language of that page, too.
Seems the lang target option in frontmatter is useless for language specific pages (maybe with an exception if you use languages.Merge …

Are you clearing the public directory before running hugo? If you ran hugo server first, the public directory will contain the internal files because the environment is development not production.

1 Like

Thank you @irkode @jmooring!

I’ve now removed the _index.md files and put the following in my hugo.toml:

[[cascade]]
    [cascade.build]
        list = 'always'
        render = 'never'
    [cascade.target]
        environment = '{development, production}'
        path = '{/internal,/internal/**}'

And now baseURL/internal, baseURL/de/internal, etc all results in Page Not Found which is exactly what I want.