Reputation: 28702
I have a .less variable, @main-color: #6a9ece;
for which I'd like to do something like @main-color: {{ user_color_selection }};
in Django.
How can I get this into my .less file?
Upvotes: 0
Views: 246
Reputation: 17263
If you're talking about specifying a colour dynamically on each page load, based on a user's preferences, then it's not a good idea to set that colour in LESS, precisely because you need to compile it on each run. Instead, apply a CSS class throughout, say .user-color
or something similar, and construct a custom stylesheet via Django templates, either as a separate view or inside the template. That class will specify the custom colour and override any defaults specified by LESS; this allows you to have a custom colour with the least amount of server work on each page load.
Alternatively, if you need to compile the LESS once universally, you might wish to look into Django commands, and write a command that would, when called, construct the LESS code on the fly and compile it to CSS immediately.
Upvotes: 2