How do I implement links whose target changes depending on a content tab? #7963
Unanswered
segfaultxavi
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Before you shoot me, allow me to explain :)
In API docs it's usual to have snippets of sample code in different programming languages, which works wonderfully with linked content tabs:
Typically a user selects a language, all tab groups in the page change to that language, and there's no need to change it anymore.
Then comes the text explaining what the code does, normally with links to pages in the API reference section.
Right now I'm using
mkdocstrings
,ezglossary
and some custom templates that give me tooltips with class and method summaries over the link. Very cool.But if I have two API sections, one for each language, which one do I link to? And which summary do I use in the tooltip?
I've been thinking a lot about the issue, let me show you the options I've found:
Put the text and the links inside the tabs. This leads to a lot of repetition, of course, so it's not good.
Add all the links after the method name, using icons:
This can be automated and looks real cute, thanks to the nice icons, but I'm having a hard time making
ezglossary
behave correctly when the link text is an icon. Plus it's going to look a bit verbose if there's more than 2 languages.Provide a custom
onclick
for the links so they jump to the currently-selected language. This is easy enough, but I lose the tooltips.Change all links every time the current language changes. This would effectively turn the links into micro-content-tabs, linked with all other content tabs, where only the content is displayed.
As a bonus, I could have different method names depending on the language, to accommodate the different naming conventions.
As an experiment, I've created the micro-content-tab in HTML, and it behaves correctly. I've even provided a custom partial for
javascripts/content.html
so the links use the correct language on page load.But I can't make them change immediately when the language is changed. I believe there's something in the bundled material js file, but it is obviously very hard to read. I'd need @squidfunk 's help for that 😅
So! What do you people think? Is there any other option? Am I missing anything?
Beta Was this translation helpful? Give feedback.
All reactions