Happy New Year, everyone!
I want to set theme dynamically on my website(discourse-based).
So I want to set different theme(I already imported some themes) in every some hours or for different domains.
Is this possible?
If this is possible, Anybody who knows about this help me to implement this please.
or Which function I should modify to implement this feature?
Thank you.
AI-generated summary
The discussion revolves around dynamically setting themes on a Discourse-based website. Lai_Chau_Koi wants to change themes every few hours or for different domains and is seeking help with implementation. Canapin suggests using Discourse’s API to enable or disable themes via a PUT request to https://yourdiscourse.com/admin/themes/[id_theme]. They provided further guidance in a follow-up post, including creating an API key, assigning an admin user, and using a JSON body to enable or disable themes.
Interesting question.
Just a guess. I suppose you can create a script that will use Discourse’s API doing a PUT request on https://yourdiscourse.com/admin/themes/[id_theme] with the body {"theme":{"enabled":false}} (false to disable or true to enable).
I may try tonight.
Sorry for the long wait. Busy day ![]()
So, you can indeed enable or disable a theme or a component with a simple API request.
You’ll have to create an API key with the right credentials and assign an admin user to it.
-
in your Discourse: admin panel → API → + New API Key
-
in the script you’ll use, as mentioned, do a PUT request on
https://yourdiscourse.com/admin/themes/[id_theme]with the proper headers (see the authentication part on https://docs.discourse.org/) and a JSON body such as:{"theme":{"enabled":false}}
This will disable the chosen theme/component. Video example with Insomnia: