# Making custom changes to the sidebar programmatically

**URL:** <https://meta.discourse.org/t/making-custom-changes-to-the-sidebar-programmatically/273027>\
**Category:** Development\
**Tags:** rest-api, sidebar\
**Created:** [July 27, 2023, 9:14am UTC](https://meta.discourse.org/t/making-custom-changes-to-the-sidebar-programmatically/273027 "2023-07-27T09:14:04Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![literarymachine](https://avatars.discourse-cdn.com/v4/letter/l/7cd45c/32.png) [@literarymachine](https://meta.discourse.org/u/literarymachine)\
**Post date:** [July 27, 2023, 9:14am UTC](https://meta.discourse.org/t/making-custom-changes-to-the-sidebar-programmatically/273027/1 "2023-07-27T09:14:04Z")

</div>

> [@Custom sidebar sections being tested on meta](https://meta.discourse.org/t/custom-sidebar-sections-being-tested-on-meta/255303/1):
>
> We have enabled the ability for you to create your own sidebar sections with links (using the enable custom sidebar sections setting).

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!

---

_[View the full topic](https://meta.discourse.org/t/making-custom-changes-to-the-sidebar-programmatically/273027)._
