Why not create a custom .LESS plugin with functions to perform the needed lookup's?
The code below was tested as shown. I don't actually look up data in a DB, but all necessary information should be available to do so. I verified that when running in Windows authentication mode on the website I was able to retrieve the current user through HttpContext.Current.User.Identity.Name
.
To use the function below you would type something like the below in your less file:
--lookup using custom function (hit db)
@brand_color:getCustomColor(usersThemeAttribute);
--then use the variable like normal
color: @brand_color;
Code
[DisplayName("UserProfilePlugin")]
public class UserProfilePlugin : IFunctionPlugin
{
public Dictionary<string, Type> GetFunctions()
{
return new Dictionary<string, Type>
{
{ "getCustomColor", typeof(GetCustomColorFunction) }
};
}
}
public class GetCustomColorFunction : Function
{
protected override Node Evaluate(Env env)
{
Guard.ExpectNumArguments(1, Arguments.Count(), this, Location);
Guard.ExpectNode<Keyword>(Arguments[0], this, Arguments[0].Location);
//the idea is that you would have many colors in a theme, this would be the name for a given color like 'bgColor', or 'foreColor'
var colorAttrName = Arguments[0] as Keyword;
//Lookup username
// string username = HttpContext.Current.User.Identity.Name;
//perform some kind of DB lookup using the username, get user theme info
// UserProfile up = new UserProfile();
// System.Drawing.Color c = up.GetColorByAttribute(colorAttrName.Value);
//return the appropriate color using RGB/etc...
// return new Color(c.R, c.G, c.B);
return new Color(129, 129, 129);
}
}
To register the plugin add this to web.config:
<dotless cache="false" >
<plugin name="UserProfilePlugin" assembly="Your.Assebly.Name" />
</dotless>
Consider disabling caching for dotless, so that changes users make take immediate effect.
Link: https://github.com/dotless/dotless/wiki/FunctionPlugins