I have a Visualforce page which has a default CSS stylesheet declared, which is always used for general styling. What I would like to do, however, is have alternate stylesheets to change brand colours on the page depending on who the user is.

  <apex:stylesheet value="{!$Resource.DefaultCSS}" />
  <apex:stylesheet value="{!IF(<useBrand>,$Resource.CustomCSS_<myBrand>}" />      <!-- this line is where I don't know what to do

So in my controller I have the variables useBrand and myBrand (based on the User), and I need to get the matching stylesheet to use that brand's colour palette.

How would I declare the custom stylesheet? If there is no brand specific info on the user, then the 2nd stylesheet is not required as everything is in the default one. The 2nd stylesheet, if used, overwrites the colours from the default one. The name of the custom stylesheet will be the same for all, except for the suffix (_myBrand).

Is there a way to declare a stylesheet based on a variable in the page controller, and to build the name of the stylesheet using the variable?

1 Answer 1


I managed to figure it out. I created a zip file with the smaller colour specific branding stylesheets, created one for the default colours too (so I don't have to do a condition). Here's what the result is, and it works perfectly.

  <apex:stylesheet value="{!$Resource.DefaulCSS}" />
  <apex:stylesheet value="{!URLFOR($Resource.CustomStyleSheets, brandStyle)}" />

brandStyle is a variable in my controller in which I put the stylesheet name (ie 'CustomStyleSheet_ABC.css').

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .