User-Centric Themes: SharePoint Branding: Part 2

Loading Different Themes Per User

In my last post I talked about audience targeted branding – using a Content Query Web Part to pull in different CSS sheets depending on which audience the user was in.

That works nicely, and being able to use audiences to gather users together is handy – but it doesn’t allow you to brand the application pages and form pages. For that you need to use a theme – and you can’t change the theme per user, it’s set once per site.

SO – I’ve come up with a neat trick to allow us to use a theme, but display a different CSS sheet to different sets of users.

General Concepts
Essentially, we’re going to use the same method as seen before – creating a custom theme on the server which references a single stylesheet deployed elsewhere (so when the theme is applied, it only links to the existing style sheet so changes to the 1 style sheet are applied globally). I have blogged this before: (http://sharepointmakesmecry.blogspot.com/2008/11/creating-global-theme-using-single-css.html)

Now we’re going to extend this idea to include multiple global style sheets – and load individual ones depending on the user logged in. This can be hugely powerful and will allow for entirely different user experiences from user to user.

Steps
1. Create our CSS files. You are best to start by copying the CSS from an existing SP theme, like Simple, and then making your changes from there. We will create a number of CSS files:
a) A ‘Common’ one – This will be used to define any styles that are shared between all users.
b) ‘Group 1 Style’ – Bare CSS, and only re-defines the individual styles for group 1.
c) ‘Group 2 Style’ – Re-defines the style for group 2.
d) ‘Group…N style’ – One CSS per individual group.

2. Upload all the CSS sheets to a common document library. This should be a Document Library somewhere in the system which is accessible by all users. Make the library readable by all.

3. Create SharePoint groups in the same site to divide the users.

4. Individually permission the CSS sheets off to SharePoint groups, so only members of ‘Group 1’ can read Group1.css, and so on.

5. Create our theme CSS file to be deployed on the server. All this file will do is list all the CSS files in the document library, and import them all at runtime:

eg.

@import:url(‘/doclibrary/common.css’);
@import:url(‘/doclibrary/group1.css’);
@import:url(‘/doclibrary/group2.css’);
…..
@import:url(‘/doclibrary/groupN.css’);

6. Deploy and apply the theme. Now when you log in all the theme files will be referenced, but most of them will be denied – leaving only the ones you have permission to read. So as you log in as users from the different SharePoint groups then you should see different CSS files loaded.

Hopefully you can see how powerful this could be!

.davros.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

About davros85

SharePoint / Azure Architect & Developer - Creator of ProvisionPoint, a site provisioning and change management solution for SharePoint Online