{"id":141,"date":"2009-12-29T16:15:45","date_gmt":"2009-12-30T00:15:45","guid":{"rendered":"http:\/\/singchan.com\/?p=141"},"modified":"2010-03-01T13:50:47","modified_gmt":"2010-03-01T21:50:47","slug":"branding-sharepoint-2010-collaboration-sites-part-2-in-a-series","status":"publish","type":"post","link":"https:\/\/singchan.com\/wordpress\/2009\/12\/29\/branding-sharepoint-2010-collaboration-sites-part-2-in-a-series\/","title":{"rendered":"Branding SharePoint 2010 Collaboration Sites &#8211; Part 2 in a Series"},"content":{"rendered":"<p>In <a title=\"Branding SharePoint 2010 Collaboration Sites - Part One\" href=\"http:\/\/singchan.com\/2009\/12\/23\/branding-sharepoint-2010-collaboration-sites-part-1-in-a-series\/\">part one<\/a> of this series on branding SharePoint 2010 collaboration sites I posted a bit about how the new Theming engine works in SharePoint 2010. In this post, we&#8217;ll be going over the new and improved <strong>CSSRegistration<\/strong> control in SharePoint 2010.<\/p>\n<h3>A history lesson; the CSSRegistration control in SharePoint 2007<\/h3>\n<p>The CSSRegistration control in SharePoint 2007 basically has one property you can set, the <strong>Name<\/strong> is the Url to the CSS file that you want to register. When you register a style sheet through the control, it adds the CSS file to an <em>alphabetically sorted<\/em> list<em>.<\/em> The style sheets in this list are then emitted as HTML &lt;link&gt; elements by the <strong>CSSLink<\/strong> control.<\/p>\n<p>If you required one CSS file to be emitted before another, you would need to name them accordingly. For example:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">&lt;SharePoint:CSSRegistration Name=&quot;foo.css&quot; runat=&quot;server&quot; \/&gt;\r\n&lt;SharePoint:CSSRegistration Name=&quot;bar.css&quot; runat=&quot;server&quot; \/&gt;<\/pre>\n<p>Even though I registered <em>foo.css<\/em> before <em>bar.css<\/em>, the HTML on the rendered page would look like so:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">&lt;link rel=&quot;stylesheet&quot; type=&quot;text\/css&quot; href=&quot;bar.css&quot;\/&gt;\r\n&lt;link rel=&quot;stylesheet&quot; type=&quot;text\/css&quot; href=&quot;foo.css&quot;\/&gt;\r\n&lt;link rel=&quot;stylesheet&quot; type=&quot;text\/css&quot; href=&quot;\/_layouts\/1033\/styles\/core.css?rev=...&quot;\/&gt;<\/pre>\n<p><em>bar.css<\/em> would come before <em>foo.css<\/em> and what&#8217;s this <em>core.css<\/em> doing here? Somehow, someone at MS decided that the core.css containing ALL of the base CSS rules for WSS should override any custom CSS!<\/p>\n<p>As a workaround, you could set the <strong>DefaultUrl<\/strong> property for the CSSLink control to point to a single CSS file that would come after core.css, and then use @import to link to any additional custom CSS files.<\/p>\n<p>The fact that core.css was emitted after any style sheets registered using CSSRegistration made the CSSRegistration control all but useless in 2007.<\/p>\n<h3>The shiny new CSSRegistration control in SharePoint 2010<\/h3>\n<p>So things are much better in the SharePoint 2010 world. If you examine the <a title=\"SDK documentation for SharePoint 2010 CSSRegistration control\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/microsoft.sharepoint.webcontrols.cssregistration_properties%28office.14%29.aspx\" target=\"_blank\">documentation for the SharePoint 2010 version of the CSSRegistration control<\/a>, you&#8217;ll find the addition of the following properties, which currently have no descriptions to their usage in the SDK:<\/p>\n<h4>RevealToNonIE (boolean)<\/h4>\n<p>I assume this property would allow you to register IE-only style sheets.\u00c2\u00a0 This doesn&#8217;t seem to be working in Beta 2 though as it doesn&#8217;t matter whether I set this to true or false, the CSS files would get emitted regardless of the browser I was using.<\/p>\n<h4>ConditionalExpression (string)<\/h4>\n<p><del datetime=\"2010-03-01T21:33:32+00:00\">Another assumption that this would allow us to set certain conditions in order for the style sheet to appear in HTML. Nothing at all in the way of documentation nor could I find any examples in the 14 Hive as of Beta 2.<\/del><\/p>\n<p>This property is an <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms537512(VS.85).aspx\" title=\"Internet Explorer Conditional Comments documentation on MSDN\">Internet Explorer Conditional Comment<\/a>. For example, if we wanted to link to a style sheet specific to IE 7 or greater, we can do this:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">&lt;SharePoint:CSSRegistration Name=&quot;foo.css&quot; ConditionalExpression=&quot;gte IE 7&quot; runat=&quot;server&quot; \/&gt;<\/pre>\n<p>The following markup would be emitted:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n&lt;!--&#x5B;if gte IE 7]&gt;\r\n&lt;link rel=&quot;stylesheet&quot; type=&quot;text\/css&quot; href=&quot;foo.css&quot;\/&gt;\r\n&lt;!&#x5B;endif]--&gt;\r\n<\/pre>\n<h4>After (string)<\/h4>\n<p>This property is what was sorely missing in 2007. We can now tell the CSSLink control to emit the registered style sheet after another CSS file. You can either define just the leaf filename, ie <em>bar.css<\/em> or the path to the CSS file, ie <em>\/foo\/bar.css<\/em>. If you don&#8217;t use the After property, style sheets will still be emitted by alphabetical order. For example:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">&lt;SharePoint:CSSRegistration Name=&quot;bar.css&quot; After=&quot;foo.css&quot; runat=&quot;server&quot; \/&gt;\r\n&lt;SharePoint:CSSRegistration Name=&quot;foo.css&quot; runat=&quot;server&quot; \/&gt;<\/pre>\n<p><em>bar.css<\/em> is emitted after <em>foo.css<\/em> because we specified the <strong>After<\/strong> property when we registered <em>bar.css<\/em>:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">&lt;link rel=&quot;stylesheet&quot; type=&quot;text\/css&quot; href=&quot;foo.css&quot;\/&gt;\r\n&lt;link rel=&quot;stylesheet&quot; type=&quot;text\/css&quot; href=&quot;bar.css&quot;\/&gt;\r\n&lt;link rel=&quot;stylesheet&quot; type=&quot;text\/css&quot; href=&quot;\/_layouts\/1033\/styles\/Themable\/corev4.css?rev=...&quot;\/&gt;<\/pre>\n<p>corev4.css IS STILL emitted after everything else for whatever reason, unless you use the <strong>After=&#8221;corev4.css&#8221;<\/strong> property when registering AND there are a few gotchas that you need to be aware of.<\/p>\n<h5>Gotcha 1: You&#8217;re never sure of the sort order<\/h5>\n<p>As of Beta 2, there&#8217;s some weirdness when you register multiple style sheets that all require to be after the same CSS file. They are no longer sorted alphabetically but in most cases they end up being last in first out:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">&lt;SharePoint:CSSRegistration Name=&quot;1.css&quot; After=&quot;corev4.css&quot; runat=&quot;server&quot; \/&gt;\r\n&lt;SharePoint:CSSRegistration Name=&quot;2.css&quot; After=&quot;corev4.css&quot; runat=&quot;server&quot; \/&gt;\r\n&lt;SharePoint:CSSRegistration Name=&quot;3.css&quot; After=&quot;corev4.css&quot; runat=&quot;server&quot; \/&gt;<\/pre>\n<p>I was expecting 1, 2, 3&#8230; but instead I get 3, 2, 1&#8230;<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">&lt;link rel=&quot;stylesheet&quot; type=&quot;text\/css&quot; href=&quot;\/_layouts\/1033\/styles\/Themable\/corev4.css?rev=...&quot;\/&gt;\r\n&lt;link rel=&quot;stylesheet&quot; type=&quot;text\/css&quot; href=&quot;3.css&quot;\/&gt;\r\n&lt;link rel=&quot;stylesheet&quot; type=&quot;text\/css&quot; href=&quot;2.css&quot;\/&gt;\r\n&lt;link rel=&quot;stylesheet&quot; type=&quot;text\/css&quot; href=&quot;1.css&quot;\/&gt;<\/pre>\n<h5>Gotcha 2: I need something AFTER another thing&#8230;<\/h5>\n<p>The other thing to take note on is when you need to define nested After. For example, I need to make sure that the style sheets are emitted in the order 1, 2, 3, 4:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">&lt;SharePoint:CSSRegistration Name=&quot;1.css&quot; runat=&quot;server&quot; \/&gt;\r\n&lt;SharePoint:CSSRegistration Name=&quot;2.css&quot; After=&quot;1.css&quot; runat=\u00e2\u20ac\u009dserver&quot; \/&gt;\r\n&lt;SharePoint:CSSRegistration Name=&quot;3.css&quot; After=&quot;2.css&quot; runat=&quot;server&quot; \/&gt;\r\n&lt;SharePoint:CSSRegistration Name=&quot;4.css&quot; After=&quot;3.css&quot; runat=&quot;server&quot; \/&gt;<\/pre>\n<p>We don&#8217;t get what we would expect the result to be, instead it comes out as 1, 4, 3, 2:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">&lt;link rel=&quot;stylesheet&quot; type=&quot;text\/css&quot; href=&quot;1.css&quot;\/&gt;\r\n&lt;link rel=&quot;stylesheet&quot; type=&quot;text\/css&quot; href=&quot;4.css&quot;\/&gt;\r\n&lt;link rel=&quot;stylesheet&quot; type=&quot;text\/css&quot; href=&quot;3.css&quot;\/&gt;\r\n&lt;link rel=&quot;stylesheet&quot; type=&quot;text\/css&quot; href=&quot;2.css&quot;\/&gt;<\/pre>\n<p>It looks like as a general rule of thumb, you should register the style sheet which comes after another one FIRST. So in order to get 1, 2, 3, 4 we need to define our registration like so:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">&lt;SharePoint:CSSRegistration Name=&quot;4.css&quot; After=&quot;3.css&quot; runat=&quot;server&quot; \/&gt;\r\n&lt;SharePoint:CSSRegistration Name=&quot;3.css&quot; After=&quot;2.css&quot; runat=&quot;server&quot; \/&gt;\r\n&lt;SharePoint:CSSRegistration Name=&quot;2.css&quot; After=&quot;1.css&quot; runat=&quot;server&quot; \/&gt;\r\n&lt;SharePoint:CSSRegistration Name=&quot;1.css&quot; runat=&quot;server&quot; \/&gt;<\/pre>\n<h4>EnableCssTheming (boolean)<\/h4>\n<p>Remember those &#8220;Themable folders&#8221; and compile time directives in the CSS files I mentioned about in Part 1? The EnableCssTheming property tells the SharePoint 2010 theming engine to recompile the style sheet using any directives found within the registered CSS file if the file&#8217;s location is in one of those &#8220;Themable&#8221; folders. EnableCssTheming is &#8220;true&#8221; by default, you have to explicitly set it to &#8220;false&#8221; if you do not want the registered style sheet to be parsed and re-compiled.<\/p>\n<p>For example:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">&lt;SharePoint:CSSRegistration Name=&quot;&lt;% $SPUrl:~sitecollection\/_layouts\/1033\/Styles\/Themable\/foo.css %&gt;&quot; runat=&quot;server&quot; \/&gt;<\/pre>\n<p>If we don&#8217;t have a theme selected, the HTML emitted will be:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">&lt;link rel=&quot;stylesheet&quot; type=&quot;text\/css&quot; href=&quot;\/_layouts\/1033\/Styles\/Themable\/foo.css&quot;\/&gt;<\/pre>\n<p>But if there&#8217;s a theme applied to a site, it will be in one of two locations, where [1234567] and [12345678] are hex values that represent the theme name and CSS file paths. The ctag QueryString parameter is a simple integer counter used for cache invalidation. It increments up every time a web&#8217;s theme gets changed.<\/p>\n<p>If the theme was applied through the web UI:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">&lt;link rel=&quot;stylesheet&quot; type=&quot;text\/css&quot; href=&quot;\/&#x5B;WEB PATH]\/_themes\/&#x5B;COUNTER]\/foo-&#x5B;12345678].css?ctag=&#x5B;COUNTER]&quot;\/&gt;<\/pre>\n<p>Or, if the theme was set programmatically using the <a title=\"SDK documentation for SharePoint 2010 ThmxTheme class\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/microsoft.sharepoint.utilities.thmxtheme%28office.14%29.aspx\" target=\"_blank\">ThmxTheme<\/a> class and shareGenerate was defined as &#8220;true&#8221; it will be located here:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">&lt;link rel=&quot;stylesheet&quot; type=&quot;text\/css&quot; href=&quot;\/_catalogs\/theme\/Themed\/&#x5B;1234567]\/foo-&#x5B;12345678].css?ctag=&#x5B;COUNTER]&quot;\/&gt;<\/pre>\n<p>Just to re-iterate, the <del datetime=\"2009-12-29T23:51:54+00:00\">two<\/del> three locations where the &#8220;Themable&#8221; folder can be located are:<\/p>\n<ol>\n<li>In the &#8220;14 hive&#8221; at <em>%ProgramFiles%\\Common Files\\Microsoft Shared\\Web Server Extensions\\14\\TEMPLATE\\LAYOUTS\\[LCID]\\STYLES\\Themable<\/em>;\n<p>Where [LCID] is the Locale ID. In North America, the default is &#8220;<strong>1033<\/strong>&#8221; for English (US).<\/p>\n<\/li>\n<li>In each web&#8217;s <em>Style Library\/Themable<\/em>. These CSS files only affect the specific web and all languages.<\/li>\n<li>In each web&#8217;s <em>Style Library\/[LANG]\/Themable<\/em>.\n<p>These CSS files only affect the specific web and a specific language. In North America, the default is &#8220;<strong>en-US<\/strong>&#8220;<\/p>\n<\/li>\n<\/ol>\n<p>You can place your CSS files inside sub-folders of Themable for neatness but not the other way around&#8230; <em>\/Style Library\/Themable\/foo\/bar.css<\/em> will be recompiled by SharePoint 2010&#8217;s theming engine while <em>\/Style Library\/foo\/Themable\/bar.css<\/em> will not.<\/p>\n<h3>In the next episode\u00e2\u20ac\u00a6<\/h3>\n<p>Whew! We&#8217;ve now gone through how to register a style sheet so that it&#8217;s compatible with the new SharePoint 2010 theming engine.<\/p>\n<p>My next post will be how to get our custom style sheets onto the out-of-the-box collaboration sites without having to create custom site templates or master pages. We&#8217;ll revisit an old friend (or new acquaintance to some), the <strong>Delegate Control<\/strong>!<\/p>\n<p><strong>UPDATE:<\/strong><\/p>\n<ul>\n<li><a title=\"Branding SharePoint 2010 Collaboration Sites: Part 1\" href=\"\/2009\/12\/23\/branding-sharepoint-2010-collaboration-sites-part-1-in-a-series\/\">You can find Part One here!<\/a><\/li>\n<li><a title=\"Branding SharePoint 2010 Collaboration Sites: Part 3\" href=\"\/2010\/02\/23\/branding-sharepoint-2010-collaboration-sites-part-3-in-a-series\/\">You can find Part Three here!<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>In part one of this series on branding SharePoint 2010 collaboration sites I posted a bit about how the new Theming engine works in SharePoint 2010. In this post, we&#8217;ll be going over the new and improved CSSRegistration control in SharePoint 2010. A history lesson; the CSSRegistration control in SharePoint 2007 The CSSRegistration control in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,25,43],"tags":[44,97,99,56,102,101,42,55,98,100,47,46],"class_list":["post-141","post","type-post","status-publish","format-standard","hentry","category-development","category-html-css","category-sharepoint-development","tag-44","tag-branding","tag-collaboration","tag-css","tag-csslink","tag-cssregistration","tag-sharepoint","tag-themes","tag-theming-system","tag-thmxtheme","tag-ue","tag-user-experience"],"_links":{"self":[{"href":"https:\/\/singchan.com\/wordpress\/wp-json\/wp\/v2\/posts\/141","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/singchan.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/singchan.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/singchan.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/singchan.com\/wordpress\/wp-json\/wp\/v2\/comments?post=141"}],"version-history":[{"count":32,"href":"https:\/\/singchan.com\/wordpress\/wp-json\/wp\/v2\/posts\/141\/revisions"}],"predecessor-version":[{"id":202,"href":"https:\/\/singchan.com\/wordpress\/wp-json\/wp\/v2\/posts\/141\/revisions\/202"}],"wp:attachment":[{"href":"https:\/\/singchan.com\/wordpress\/wp-json\/wp\/v2\/media?parent=141"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/singchan.com\/wordpress\/wp-json\/wp\/v2\/categories?post=141"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/singchan.com\/wordpress\/wp-json\/wp\/v2\/tags?post=141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}<!-- WP Super Cache is installed but broken. The constant WPCACHEHOME must be set in the file wp-config.php and point at the WP Super Cache plugin directory. -->