Set Theme Dynamically

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.

3 Likes

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.

1 Like

Sorry for the long wait. Busy day :technologist:

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:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.