Skip to content

bugfix: nested sidebar_root_for - #2470

Merged
chalin merged 3 commits into
docsy:mainfrom
reidmv:bugfix-nested-sidebar_root_for
Jan 24, 2026
Merged

chalin merged 3 commits into
docsy:mainfrom
reidmv:bugfix-nested-sidebar_root_for

Conversation

@reidmv

@reidmv reidmv commented Jan 21, 2026 •

Copy link
Copy Markdown
Contributor

Previously, when attempting to use nested sidebar_root_for directives, the sidebar root displayed would be inconsistent for nested "self" directives (the self page would have the correct sidebar, but not its children), and ineffective for nested "children" directives.

Investigation pointed to searching the ancestors collection in reverse order.

Hugo documentation for the Ancestors method states:

Hugo orders the ancestors from closest to furthest.

See https://gohugo.io/methods/page/ancestors/.

The list returned by the Ancestors method is already in "reverse" order, with the deepest (closest) ancestor first. Calling Reverse on it gives a list with the root first, meaning that we will find the highest-level sidebar_root_for page, rather than the lowest level.

This commit removes the Reverse directive. sidebar_root_for directives can now be nested correctly.


Previously, when attempting to use nested sidebar_root_for directives,
the sidebar root displayed would be inconsistent for nested "self"
directives, and ineffective for nested "children" directives.

Investigation pointed to searching the ancestors collection in reverse
order.

Hugo documentation for the Ancestors method states:
> Hugo orders the ancestors from closest to furthest.

See https://gohugo.io/methods/page/ancestors/.

The list returned by the Anscestors list is already in "reverse" order;
calling Reverse on it gives a list with the root first, meaning that we
will find the highest-level sidebar_root_for page, rather than the
lowest level.

This commit removes the Reverse directive. sidebar_root_for directives
can now be nested correctly.
@chalin

chalin commented Jan 24, 2026 •

Copy link
Copy Markdown
Collaborator

Hi @reidmv. Thanks for reporting the issue, the analysis, and proposed fix. Well done 🙌🏻

when attempting to use nested sidebar_root_for directives, the sidebar root displayed would be inconsistent for nested "self" directives (the self page would have the correct sidebar, but not its children), and ineffective for nested "children" directives.

Let me get a repro first. Let's track this via:

@chalin chalin added this to the 0.14.0 milestone Jan 24, 2026
@chalin chalin added the UX label Jan 24, 2026

@chalin chalin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌 ✨

@chalin
chalin merged commit 11bc51a into docsy:main Jan 24, 2026
@chalin

chalin commented Jan 24, 2026

Copy link
Copy Markdown
Collaborator

I was sure I had tested nested scenarios, but maybe not 🤷🏼‍♂️. Thanks again @reidmv!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Problem with nested sidebar_root_for directives

2 participants