{"id":181,"date":"2010-02-23T08:04:48","date_gmt":"2010-02-23T16:04:48","guid":{"rendered":"http:\/\/singchan.com\/?p=181"},"modified":"2010-02-23T08:14:01","modified_gmt":"2010-02-23T16:14:01","slug":"branding-sharepoint-2010-collaboration-sites-part-3-in-a-series","status":"publish","type":"post","link":"https:\/\/singchan.com\/wordpress\/2010\/02\/23\/branding-sharepoint-2010-collaboration-sites-part-3-in-a-series\/","title":{"rendered":"Branding SharePoint 2010 Collaboration Sites &#8211; Part 3 in a Series"},"content":{"rendered":"<p>In <a href=\"http:\/\/singchan.com\/2009\/12\/29\/branding-sharepoint-2010-collaboration-sites-part-2-in-a-series\/\" title=\"Branding SharePoint 2010 Collaboration Sites - Part 2 in a Series\">part two<\/a>, we posted about how to register our custom style sheets in a way that we could still take advantage of the new SharePoint 2010 colour switching theming engine. In this post we&#8217;ll go through how to do this without having to modify the out-of-the-box master pages or having to use custom master pages for your sites.<\/p>\n<h3>Delegate Controls<\/h3>\n<p>As I mentioned at the end of part two, the way we&#8217;re going to get our CSS added to our sites and pages is through the use of a <strong>delegate control<\/strong>. For those of you who aren&#8217;t familiar with delegate controls, they are essentially placeholders for you to inject your own controls via a feature. Your feature can be scoped to either <em>Web<\/em>, <em>Site<\/em>, <em>WebApplication<\/em> or <em>Farm<\/em>. I&#8217;m going to keep the explanation on delegate controls short as there&#8217;s plenty of information out there about them:<\/p>\n<ul>\n<li><a href=\"http:\/\/www.sharepointnutsandbolts.com\/2007\/06\/using-delegate-control.html\">Chris O&#8217;Brien: Using the Delegate Control<\/a><\/li>\n<li><a href=\"http:\/\/www.devx.com\/enterprise\/Article\/36628\/1954\">SharePoint&#8217;s Delegate Control Power<\/a><\/li>\n<li><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/microsoft.sharepoint.webcontrols.delegatecontrol%28office.14%29.aspx\">MSDN 2010 SDK: DelegateControl Class<\/a><\/li>\n<\/ul>\n<div id=\"attachment_204\" style=\"width: 160px\" class=\"wp-caption alignright\"><a href=\"https:\/\/singchan.com\/wordpress\/wp-content\/uploads\/2010\/02\/AdditionalPageHead.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-204\" src=\"https:\/\/singchan.com\/wordpress\/wp-content\/uploads\/2010\/02\/AdditionalPageHead-150x150.png\" alt=\"Screenshot of AdditionalPageHead delegate control in v4.master\" title=\"AdditionalPageHead Delegate Control\" width=\"150\" height=\"150\" class=\"size-thumbnail wp-image-204\" \/><\/a><p id=\"caption-attachment-204\" class=\"wp-caption-text\">AdditionalPageHead Delegate Control<\/p><\/div>\n<h3>The AdditionalPageHead Delegate<\/h3>\n<p>Delegate controls have a <strong>AllowMultipleControls<\/strong> property which when set to <em>true<\/em>, all controls keyed to that delegate are added to the page; when set to <em>false<\/em>, only the control registered with the lowest <em>sequence<\/em> value is added to the page.<\/p>\n<p>All of the delegate controls in the OOTB master pages have <strong>AllowMultipleControls<\/strong> set to <em>false<\/em>, with the exception of one, <strong>AdditionalPageHead<\/strong>, which does allow multiple controls. And guess what? AdditionalPageHead is actually located in the page head, where you would normally add CSS <link> elements! This is the perfect place for us to inject any CSS registration controls.<\/p>\n<h3>Putting it all together&#8230;<\/h3>\n<p>Let&#8217;s put together a simple solution using the Visual Studio 2010 SharePoint Tools which will:<\/p>\n<ol>\n<li>deploy our CSS file in the <strong>Themable<\/strong> folder in the <em>\/Layouts\/1033\/Styles<\/em><\/li>\n<li>deploy a user control into the <em>ControlTemplates<\/em> folder which uses the <strong>CSSRegistration<\/strong> control to register our CSS<\/li>\n<li>install a feature which inserts our user control onto our pages via the <strong>AdditionalPageHead<\/strong> delegate<\/li>\n<\/ol>\n<h4>The CSS<\/h4>\n<p>Keeping it simple, all our CSS does is set the background color of the &lt;body&gt;. We&#8217;ll use #FFF (white) as our default background color and also decorate the rule with one of the SharePoint 2010 compile time directives to whatever we might set the &#8220;Light1&#8221; color value as through the Theme UI.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nbody {\r\n\/*&#x5B;ReplaceColor(themeColor:&quot;Light1&quot;)]*\/\r\nbackground-color: #fff;\r\n}\r\n<\/pre>\n<h4>The Delegate Control<\/h4>\n<p>Again, nice and simple, we&#8217;re going to use the CSSRegistration control to register our branding CSS after corev4.css:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n&lt;%@ Assembly Name=&quot;$SharePoint.Project.AssemblyFullName$&quot; %&gt;\r\n&lt;%@ Register Tagprefix=&quot;SharePoint&quot; Namespace=&quot;Microsoft.SharePoint.WebControls&quot; Assembly=&quot;Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&quot; %&gt;\r\n\r\n&lt;sharepoint :CSSRegistration Name=&quot;&lt;% $SPUrl:~sitecollection\/_layouts\/1033\/Styles\/Themable\/SingChan.SP2010.Branding\/branding.css %&gt;&quot; After=&quot;corev4.css&quot; runat=&quot;server&quot; \/&gt;\r\n&lt;\/sharepoint&gt;\r\n<\/pre>\n<h4>Element Manifest<\/h4>\n<p>And finally we&#8217;ll define our element manifest for our delegate feature:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;\r\n&lt;elements xmlns=&quot;http:\/\/schemas.microsoft.com\/sharepoint\/&quot;&gt;\r\n    &lt;control Id=&quot;AdditionalPageHead&quot; Sequence=&quot;80&quot; ControlSrc=&quot;~\/_ControlTemplates\/SingChan.SP2010.Branding\/CSSRegistrationControl.ascx&quot; \/&gt;\r\n&lt;\/elements&gt;\r\n<\/pre>\n<p>You&#8217;ll most likely scope your delegate feature to either <em>Web<\/em> or <em>Site<\/em> for branding purposes. I tend to scope my feature at the site collection level to achieve a consistent brand across all the webs in the site collection. If there&#8217;s a requirement to have different branding for one or two specific sites, then we can always have a second feature which deploys those overrides at a web-level scope. If you have vastly different brands across webs in your site collection, then you may want to scope only at the web level so that your brands don&#8217;t conflict or end up with any style inheritance issues.<\/p>\n<h3>That&#8217;s it!<\/h3>\n<p>If all went well, we should see the link to our style sheet emitted after the link to corev4.css!<br \/>\n<div id=\"attachment_210\" style=\"width: 160px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/singchan.com\/wordpress\/wp-content\/uploads\/2010\/02\/brandingcss.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-210\" src=\"https:\/\/singchan.com\/wordpress\/wp-content\/uploads\/2010\/02\/brandingcss-150x150.png\" alt=\"Screen shot of HTML source of page containing a link to the branding CSS.\" title=\"Branding CSS in HTML Source\" width=\"150\" height=\"150\" class=\"size-thumbnail wp-image-210\" \/><\/a><p id=\"caption-attachment-210\" class=\"wp-caption-text\">Our branding CSS being emitted in HTML<\/p><\/div><\/link>\n<p>If all is not well, here&#8217;s the ZIP file containing the branding VS2010 solution for reference:<br \/>\n<a href='https:\/\/singchan.com\/wordpress\/wp-content\/uploads\/2010\/02\/SingChan.SP2010.Branding.zip' title=\"ZIP file containing the branding VS2010 solution\">SingChan.SP2010.Branding.zip<\/a><\/p>\n<h3>Previously&#8230;<\/h3>\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 2\" href=\"\/2009\/12\/29\/branding-sharepoint-2010-collaboration-sites-part-2-in-a-series\/\">You can find Part Two here!<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>In part two, we posted about how to register our custom style sheets in a way that we could still take advantage of the new SharePoint 2010 colour switching theming engine. In this post we&#8217;ll go through how to do this without having to modify the out-of-the-box master pages or having to use custom master [&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,99,56,58,104,57,45,55,98,47,46],"class_list":["post-181","post","type-post","status-publish","format-standard","hentry","category-development","category-html-css","category-sharepoint-development","tag-44","tag-collaboration","tag-css","tag-custom","tag-delegatecontrol","tag-master-page","tag-spc09","tag-themes","tag-theming-system","tag-ue","tag-user-experience"],"_links":{"self":[{"href":"https:\/\/singchan.com\/wordpress\/wp-json\/wp\/v2\/posts\/181","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=181"}],"version-history":[{"count":18,"href":"https:\/\/singchan.com\/wordpress\/wp-json\/wp\/v2\/posts\/181\/revisions"}],"predecessor-version":[{"id":224,"href":"https:\/\/singchan.com\/wordpress\/wp-json\/wp\/v2\/posts\/181\/revisions\/224"}],"wp:attachment":[{"href":"https:\/\/singchan.com\/wordpress\/wp-json\/wp\/v2\/media?parent=181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/singchan.com\/wordpress\/wp-json\/wp\/v2\/categories?post=181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/singchan.com\/wordpress\/wp-json\/wp\/v2\/tags?post=181"}],"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. -->