Skip to content

What's the right way to set per-page secondary sidebar content? #1535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
peytondmurray opened this issue Oct 20, 2023 · 6 comments · Fixed by #1572
Closed

What's the right way to set per-page secondary sidebar content? #1535

peytondmurray opened this issue Oct 20, 2023 · 6 comments · Fixed by #1572

Comments

@peytondmurray
Copy link
Contributor

I'm building my docs with the latest verison of pydata-sphinx-theme. I'd really like to have the secondary sidebar show up everywhere except in the docs landing page (index). I noticed that the PST docs don't have a secondary sidebar on the landing page. From what I can tell, those docs are just using the default value for theme_secondary_sidebar_items, so I'm wondering if there's something more I need to do to prevent the secondary sidebar from rendering on the index.

As a related issue, it would be nice to be able to set secondary sidebar templates on a per-page basis in the same way that we can already do by providing a dictionary to html_sidebars.

@12rambau
Copy link
Collaborator

@peytondmurray
Copy link
Contributor Author

This addresses my use case but it would still be nice to set secondary sidebar content on a per-page basis (if we can do this with the primary sidebar, why not the secondary?). Thanks for the help! I'll keep this open since it seems like this isn't currently possible and might be a nice feature to add.

@drammock
Copy link
Collaborator

it would still be nice to set secondary sidebar content on a per-page basis (if we can do this with the primary sidebar, why not the secondary?)

the answer to "why not the secondary?" is that setting the primary sidebar content on a per-page basis is a feature of sphinx itself, not a feature of the theme. I suspect it would entail re-implementing a lot of sphinx machinery (and/or relying on aspects of the sphinx API that are not meant to be public) in order to get it to work.

That's not to say we can't or won't do it someday, but my educated guess (without having tried any experiments) is that it would be hard. PR welcome from any motivated users :)

@peytondmurray
Copy link
Contributor Author

@drammock Well, I figure we could just have a template that calls out to a python function to render secondary sidebar content depending on the current pagename. In any case if you'd like we can close this one out if it's too much work.

@drammock
Copy link
Collaborator

drammock commented Nov 15, 2023

I figure we could just have a template that calls out to a python function to render secondary sidebar content depending on the current pagename

hmm. that could work. I guess we could accept current configs like

html_theme_options["secondary_sidebar_items"] = ['list', 'of', 'templates']

and internally convert them to

html_theme_options["secondary_sidebar_items"] = {"**": ['list', 'of', 'templates']}

and then in src/pydata_sphinx_theme/theme/pydata_sphinx_theme/sections/sidebar-secondary.html use Jinja to check pagename against keys in that dictionary (on the assumption that users can add additional, more specific keys for pages they want to customize).

So, unless I'm missing something, not actually that hard. Thanks for pushing back on my pessimistic assessment. Wanna give it a shot?

@peytondmurray
Copy link
Contributor Author

I'd love to! I'll make a PR later this week, if that works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants