Branding: Relative URLS in SharePoint Masterpage

The scenario

You have a bunch of CSS files stored in the Styles Library ofa site collection. Your masterpage references the CSS files in the style library using the following code:

<SharePoint:CSSRegistration name=”Style Library/myCSS.css” After=”corev4.css runat=”server”/>

Everything works fine so you decide to deploy the branding files to another site collection.

After applying the new masterpage, you get an error saying that the masterpage cannot find the CSS files referenced in the masterpage.

The reason for this is because the path defined in the CSSRegistration tag begins with /Style Library. This means that the masterpage will always try to look for the files in http://sharepoint.site/Style Library. To make it look for the files from the root of each site collection, you need to use the $SPUrl token in the file path.

<SharePoint:CSSRegistration name=”<% $SPUrl:~sitecollection/Style Library/myCSS.css %>” After=”corev4.css” runat=”server” />

Tags:

No comments yet.

Leave a Reply

%d bloggers like this: