Maybe my longest title for a post ever but I think it covers everything what I wanted to share with you.. In a previous post I mentioned a solution for a problem when a site template was being used with activated features that didn't provision very well. This post is about that solution ;)
It's not really difficult to create a new site definition (a lot of bloggers already paved the way for me there) but I had some difficulties adding a Content Editor WebPart (CEWP) with HTML into my definition. Since you have to replace the < and > symbols with &tl; and > and you will have to put CDATA brackets around the whole thing as well. After several attempts to encode my HTML the proper way (and failing miserably), I decided to check how Microsoft put CEWP's in their site templates.. and this is how it looks:
<WebPart xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/WebPart/v2">
<Title>$Resources:spscore,ReportCenterOnet_CEWP_Title;</Title>
<FrameType>TitleBarOnly</FrameType>
..
<Assembly>Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
<TypeName>Microsoft.SharePoint.WebPartPages.ContentEditorWebPart</TypeName>
<ContentLink xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
<Content xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor">$Resources:spscore,ReportCenterOnet_CEWP_Content;</Content>
<PartStorage xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
</WebPart>
"$Resources:spcore, ReportCenterOnet_CEWP_Content", that's all the content they put in there! No encoded HTML with CDATA brackets at all! So what does it mean then? Well.. i'll tell you!
- $Resources : here they are referring to the fact that the content is placed in the Resources folder (/12 hive/Resources)
- spcore : here they are referring to which file the content is placed in
- ReportCenterOnet_CEWP_Content : here they are referring to which value in the file must be used
So when we open up the spcore.xml file and find look for the "ReportCenterOnet_CEWP_Content" value, it looks like this :
<Data Name="ReportCenterOnet_CEWP_Content">
<Value><DIV class="ms-vb">
<SPAN class="ms-announcementtitle">Report Center features include:</SPAN>
<UL>
<LI><A title="" href="../Lists/Sample KPIs/KPIListViewPage.aspx" target="">Key Performance Indicators</A> (KPIs) enable you to communicate goals, trends and track progress.</LI>
<LI><A title="" href="../ReportsLibrary/sample dashboard.aspx" target="">Dashboards</A> enable you to give a more detailed explanation of your information using Excel workbooks and KPIs. Dashboard filters make it easy to select a range of information to view. To create your own dashboard go to the <A title="" href="../ReportsLibrary/Forms/scsummpg.aspx" target="">Dashboards</A> view of the Reports library and click 'New'.</LI>
<LI>The <A title="" href="../ReportsLibrary/forms/current.aspx" target="">Reports</A> library is designed to store files containing reports and dashboards and allow easy access to information from previous time periods.</LI>
</UL>
<SPAN class="ms-announcementtitle">To prepare this Report Center for use, the following actions are suggested:</SPAN>
<UL>
<LI>View the sample <A href="../ReportsLibrary/sample dashboard.aspx">dashboard</A> and <A title="" href="../ReportsLibrary/sampleworkbook.xlsx" target="">workbook</A> to understand some of the capabilities of this Report Center</LI>
<LI>If the samples do not work correctly ask an administrator to ensure that Excel Services are enabled and that this Report Center is a Trusted Location</LI>
<LI>If you plan to use Excel to analyze information from existing data servers, create and upload data connection (ODC) files to the <A title="" href="../Data Connections" target="">Data Connection Library</A>. If you want users to create new KPI Lists then add them to the "Owners" group. Users in the "Members" group can edit pages but can not create KPI Lists.</LI>
<LI>Update or remove sample content</LI>
</UL>
</DIV></Value>
</Data>
So it seems you still have to encode your HTML but you don't have to worry about CDATA stuff :) The question is, why should you use the same technique as Microsoft does ?
- Makes the ONET.XML more 'readible' and thus easier to maintain
- No more messing around where to put the CDATA stuff
- One place to maintain the content of your CEWPs
Hope this gives you more insight about creating and defining site definitions as it did to me ;)
Technorati Tags:
Customization