This is a great feature, but what if the content of a custom sidebar section needs to be created programmatically? I have achieved this in a way similar to @Olya_Fursova above, only that the content is generated by querying the API and then rendering links, some to categories and some directly to certain topics. Two problems I encountered are:
If the sidebar is hidden when the page is initially rendered, the dynamic content won’t be shown since the sidebar container is not present. Also, when the sidebar is initially shown but then collapsed and shown again, the dynamic content is gone because the sidebar container is re-rendered without the custom logi being executed. Question: is there any way to hook into the sidebar rendering process to execute my custom code whenever the sidebar is shown?
When the links I add to the sidebar programmatically are clicked, the complete page is refreshed. Question: is there any way to prevent a complete page refresh when one of my custom links in the sidebar is clicked?
It would be really fantastic if there was a way to modify the sidebar programmatically!
This looks interesting, thanks! Will take some time to really grasp it though, e.g. I don’t really get the hang of the routing yet. Also, it looks like the links in a section can only be a flat list, right? What I am currently trying to achieve is something like this, i.e. one level of indention:
Is this something I can achieve with the new API for custom sidebar sections?
No, we haven’t built any sort of indentation into the sidebar by default… but as long as you can get your sections in the order that you want with the API, I think the indenting can probably be handled with styling in CSS?
Having looked into it a bit further, I am confident that this will work, yes! My challenge now is that the list of links is dynamic and can potentially change with each page change. My naive approach of calling api.addSidebarSection from within api.onPageChange does not work because (a) the sidebar is only refreshed when it is re-rendered by hiding and showing it again and (b) the sections are repeated because api.addSidebarSection does not care if the name key is reused.
Any chance I can achieve a sidebar section that is updated on each page transition with the new API?