0

I have a sets of users that I need to create themes for. Depending on the user's account association I want to load different themes. For example if John Doe logs in I need to load up greenteam.scss. However, if Doug Smith logs in he should see blueteam.scss.

Those files are basically color and font settings used by other elements. greenteam may have $header-bg: green; and blueteam would have $header-bg: blue;.

My initial thought is to have a structure like this: /src/scss/client/_client-xxx.scss that says the background colors, font colors, etc variables set in the application. So, after login the system is told the person logged in is part of "greenteam" and /src/scss/client/_client-greenteam.scss is loaded to compile the colors and other settings together. This way I can just drop the new client theme in the directory and boom, new theme!

The number of "teams" is going to grow exponentially. I have no idea how many I'll ever have at any given point. This is why the "just change the body class" is worrisome as that will get very big and hard to manage.

It's also possible I don't have a good grasp on how angular builds itself out on the web as a user calls the pages/styles. It appears, at a glance, when deployed on the server angular compiles the scss down to css in the header and not loaded "on the fly". If that's the case it seems I'd have to load all the possible client css options and just show what matches (the body class route).

The user won't have control over their theme directly or be able to change it, the theme will be customized manually by a developer.

dcp3450
  • 10,959
  • 23
  • 58
  • 110

1 Answers1

0

I would have suggested to change the body class, but, if you really want to apply css at runtime, you could try to:

  1. compile the scss to css
  2. insert it in the dom at runtime depending on the user

Check this topic which tells how to add a style at runtime, you could get the text content of the stylesheet from a database: https://stackoverflow.com/a/524717/10899694