I'm using Django and Bootstrap. I come to you with a total of 3 interconnected problems, if you come up with a better idea on how to do all of this, I'm open to suggestions. Thanks in advance.
I have a base template which is extended by other templates and it contains navigation, in which I would like to have the name of the currently selected theme displayed. After clicking on this name, I want to have the option to select one of three themes: light, dark, custom. I started to do this using a dropdown:
<li class="nav-item dropdown">
<button class="nav-link dropdown-toggle" id="navbarThemeDropdown" type="button" data-bs-toggle="dropdown" aria-expanded="false">
Theme: Light <i class="bi bi-sun-fill"></i>
</button>
<div class="dropdown-menu" aria-labelledby="navbarThemeDropdown">
<button class="dropdown-item d-flex justify-content-between" type="button">
Light <i class="bi bi-sun-fill"></i>
</button>
<button class="dropdown-item d-flex justify-content-between" type="button">
Dark <i class="bi bi-moon-fill"></i>
</button>
<button class="dropdown-item d-flex justify-content-between" type="button">
Custom <i class="bi bi-palette-fill"></i>
</button>
</div>
</li>
Following the documentation https://getbootstrap.com/docs/5.3/customize/color-modes/#enable-dark-mode to apply the theme for all elements on the page, I thought to use a context processor, which will read the theme value from cookies:
<html lang="en" data-bs-theme="{{theme}}">
context_processors.py:
def theme(request):
return {'theme': request.COOKIES.get('theme', 'light')}
But I don't know how to set these cookies after choosing one of the themes. Also notice that the theme function returns 'light' when there is no cookie, but it should also set this cookie then.
Logged in user should be able to choose colors of the navigation, the background of the page, and the background of Bootstrap cards for the custom theme in account settings. I thought to create the custom theme roughly like this:
base.css:
[data-bs-theme="custom"] {
--bs-body-bg: var(--body-bg);
--bs-navbar-bg: var(--navbar-bg);
--bs-card-bg: var(--card-bg);
But I also don't know how to fetch these variables and whether I should store these colors in the database, creating three columns.