Using different list template by depth

I have the following content structure, i would like to use different list templates for site.com/stories and site.com/stories/18273-story-1/. Any suggestions will be appreciated.

content/
    stories/ <- template A
          18273-story-1/ <- template B
                _index.md
                1.md
                2.md
                ...
                10.md
          73462-story-2/
                1.md
                2.md
                ...
                20.md

[Not tested]

Apply template B to all the stories section lists: stories/list.html.

The template A only for the stories list page: stories/index.html (or layout: call in the frontmatter).

Edit: The @bep solution is better than mine :wink:

I think the currently simplest solution is to set either type (recommended) or layout with cascade; you should be able to match the levels with a Glob:

[[cascade]]
type = "b-type"
[cascade._target]
path = "/stories/*/**"

Note that cascade can be set both in front matter and in site config.

2 Likes

I think Hugo’s TOML parser supports “dot syntax”, so the above could probably be made into:

[[cascade]]
type = "b-type"
_target.path = "/stories/*/**"

Which is easier to read.

1 Like

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