现在的位置: 首页 > 综合 > 正文

MOSS 2007 Publishing web site definition template – onet.xml – syntax for properties and getting the right content types

2013年11月19日 ⁄ 综合 ⁄ 共 8526字 ⁄ 字号 评论关闭

The documentation for creating site definitions and provisioning for MOSS 2007 Publishing sites is almost non-existing on MSDN.

My first suggestion is to look at the out of the box publishing site definition “BLANKINTERNET”.
This site definition is located in the 12 hive: C:/Program Files/Common Files/Microsoft Shared/web server extensions/12/TEMPLATE/SiteTemplates/BLANKINTERNET
The template configuration for this site definition can be found in the file: C:/Program Files/Common Files/Microsoft Shared/web server extensions/12/TEMPLATE/1033/XML/webtempsps.xml. Note that only the part in the element <Template Name="BLANKINTERNET" ID="53">... is applicable.

I will post a more complete article on how to create your own publishing site definition with custom page layouts, master pages and content types later when I have more time... For now I’ll just go over the elements on which I had most work getting them to work. It’s actually not quite hard as long as you know how to do it.

1. Make sure the required onet.xml and webtemp*.xml files are copied to the right directories

Your onet.xml file should go into the folder C:/Program Files/Common Files/Microsoft Shared/web server extensions/12/TEMPLATE/SiteTemplates/[YOURSITEDEF]/XML
Provisioned files may go one level higher: C:/Program Files/Common Files/Microsoft Shared/web server extensions/12/TEMPLATE/SiteTemplates/[YOURSITEDEF]

webtemp*.xml file should go into: C:/Program Files/Common Files/Microsoft Shared/web server extensions/12/TEMPLATE/1033/XML

2. onet.xml: referencing the correct site features

In order to get the publishing site features activated when you create a site based on your custom site template, make sure all required publishing site and web features are activated. Features at site level are defined and activated at the site collection level. Web features will be activated for every new web you create using this configuration.

...

<!-- part ommitted for clarity -->
<
Configurations>
<
Configuration ID="-1" Name="NewWeb"/>

<

Configuration ID="0" Name="[YOURSITEDEF]">

<

SiteFeatures>

<!--

Workflow Features -->
<!--
Workflow Expiration -->

<

Feature ID="C85E5759-F323-4EFB-B548-443D2216EFB5" />

<!--

Workflow Review -->
<
Feature ID="02464C6A-9D07-4F30-BA04-E9035CF54392" />

<!--

Workflow Signature -->
<
Feature ID="6C09612B-46AF-4B2F-8DFC-59185C962A29" />

<!--

Workflow Translation -->
<
Feature ID="C6561405-EA03-40A9-A57F-F25472942A22" />

<

Feature ID="A392DA98-270B-4e85-9769-04C0FDE267AA">

<!--

PublishingPrerequisites -->

</

Feature>

<

Feature ID="7C637B23-06C4-472d-9A9A-7C175762C5C4">

<!--

ViewFormPagesLockDown -->

</

Feature>

<

Feature ID="AEBC918D-B20F-4a11-A1DB-9ED84D79C87E">

<!--

PublishingResources -->

<

Properties xmlns="http://schemas.microsoft.com/sharepoint/">
<
Property Key="AllowRss" Value="false"/>
<
Property Key="SimplePublishing" Value="false" />
</
Properties>

</

Feature>

<

Feature ID="F6924D36-2FA8-4f0b-B16D-06B7250180FA">

<!--

Office SharePoint Server Publishing -->

</

Feature>

</

SiteFeatures>

<

WebFeatures>

<!--

Include the common WSSListTemplateFeatures used by CMS -->

<

Feature ID="00BFEA71-DE22-43B2-A848-C05709900100" > </Feature>

<

Feature ID="00BFEA71-E717-4E80-AA17-D0C71B360101" > </Feature>

<

Feature ID="00BFEA71-52D4-45B3-B544-B1C71B620109" > </Feature>

<

Feature ID="00BFEA71-A83E-497E-9BA0-7A5C597D0107" > </Feature>

<

Feature ID="00BFEA71-4EA5-48D4-A4AD-305CF7030140" > </Feature>

<

Feature ID="22A9EF51-737B-4ff2-9346-694633FE4416">

<!--

Publishing -->

<

Properties xmlns="http://schemas.microsoft.com/sharepoint/">
<
Property Key="ChromeMasterUrl" Value="~SiteCollection/_catalogs/masterpage/mymasterpage.master"/>
<
Property Key="WelcomePageUrl" Value="$Resources:cmscore,List_Pages_UrlName;/default.aspx"/>
<
Property Key="PagesListUrl" Value=""/>
<
Property Key="AvailableWebTemplates" Value="*-MYSITEDEF#1"/>
<
Property Key="AvailablePageLayouts" Value="~SiteCollection/_catalogs/masterpage/mypagelayout.aspx"/>
<
Property Key="AlternateCssUrl" Value="" />
<
Property Key="SimplePublishing" Value="false" />

</

Properties>

</

Feature>

<

Feature ID="541F5F57-C847-4e16-B59A-B31E90E6F9EA">

<!--

Per-Web Portal Navigation Properties-->

<

Properties xmlns="http://schemas.microsoft.com/sharepoint/">

<

Property Key="InheritGlobalNavigation" Value="true"/>

<

Property Key="IncludeSubSites" Value="true"/>

</

Properties>

</

Feature>

<

Feature ID="94C94CA6-B32F-4da9-A9E3-1F3D343D7ECB">

<!--

Office SharePoint Server Publishing -->

</

Feature>

</

WebFeatures>

<!--

remaining elements ommitted -->

</

Configuration>

3. The right syntax for AvailablePageLayouts and AvailableWebTemplates

The Publishing Web Feature (ID 22A9EF51-737B-4ff2-9346-694633FE4416) contains some properties that allow us to specify master pages, page layouts and available web templates.

The syntax for specifying the values in the onet.xml file is not documented (as far as I could find).

AvailablePageLayouts

Your custom page layout should be deployed to the site collection by activating a page layout provision feature for example.

For a single page layout, the syntax is available in the BLANKINTERNET site definition:

<

Property Key="AvailablePageLayouts" Value="~SiteCollection/_catalogs/masterpage/mypagelayout.aspx"/>

For defining multiple AvailablePageLayouts I found that the separator is : (colon) by looking at the Search site definition (SRCHCEN):

<

Property Key="AvailablePageLayouts" Value="~SiteCollection/_catalogs/masterpage/
mypagelayout.aspx:~SiteCollection/_catalogs/masterpage/mypagelayout2.aspx
"/>

AvailableWebTemplates

If you want to restrict the list of available web templates you can do this with the AvailableWebTemplates property.

<

Property Key="AvailableWebTemplates" Value="*-MYSITEDEF#1"/>

For specifying multiple web templates, I found the syntax thanks to a post in a forum: http://www.eggheadcafe.com/software/aspnet/29217247/availablewebtemplates-key.aspx

Someone found the syntax by looking at the Microsoft.SharePoint.Publishing.PublishingWeb class using reflector. Snippet from the solution mentioned in the forum:

AvailableWebTemplates Key Format is:
LCID-[sitetemplatename][#sitetemplatenumber];LCID-[sitetemplatename]
[#sitetemplatenumber];LCID-[sitetemplatename][#sitetemplatenumber]

1033-BLANKINTERNET#1;1049- BLANKINTERNET #1;*- BLANKINTERNET #2

*-BLANKINTERNET#2 - ALL Languages
(Thanks Sorgi?)

So if we know the separator is ; (semi-colon) the element should look like:

<

Property Key="AvailableWebTemplates" Value="*-MYSITEDEF#1;*-MYSITEDEF#3"/>

Please see the Microsoft.SharePoint.Publishing.PublishingWeb class reference on MSDN: http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.publishing.publishingweb.aspx. Looking at the class properties will also give you more insight into how to use the properties in the onet.xml file.

4. Using multiple configuration and hiding them in the UI

The webtemp*.xml file may contain multiple template configurations. You may make some of these hidden for example if you want to create those specific sites via code only. Use for Hidden="TRUE" this.

webtemp*.xml snippet:

<!--

... snippet:-->

<

Template Name="MYSITEDEF" ID="10020">

<

Configuration ID="0" Title="My site template" Hidden="FALSE" ImageUrl="/_layouts/1033/images/img.gif" Description="This is a publishing site template" SubWebOnly="FALSE" DisplayCategory="My own category">

</

Configuration>

<

Configuration ID="1" Title="My site template – Autocreated contact section" Hidden="TRUE" ImageUrl="/_layouts/1033/images/img.gif" Description="This template is used by code to generate the contact site." SubWebOnly="TRUE" DisplayCategory=" My own category" VisibilityFeatureDependency="97B7C2D9-51E6-4add-844E-D133D25B7B15">

</

Configuration>

<!--

... snippet end-->

5. Making your own content types available

When you use custom page layouts chances are you are also using custom content types. By using the AvailablePageLayouts properties your custom page layouts become available but there is still a problem. By default the Pages library only contains the MOSS publishing content types, as you can see in this screenshot:

Users will be available to create new pages using your page layout but all the custom properties you use in their related content types are missing. The page layout may not show any property in edit mode. If you go the Site Settings > Site content types, you will see your custom content types and their site columns.
You may manually add the content types to the Pages library by going to Site Actions > Site Settings > Modify Pages Library Settings. Choose “Add from existing site content types” and choose the content types. Once this is done your custom page layouts should start working normally.
Doing the manual setting is one possibility but having to do this manually for every new web is not really an option.
I ended up creating a web feature that is automatically activated by the site template definition. My feature contains a ReceiverAssembly and class in which I add the desired content types to the Pages library.

Code snippet:

string

pageLib = Microsoft.SharePoint.Publishing.PublishingWeb.GetPagesListName(web);

SPContentTypeCollection allContentTypes = web.Site.RootWeb.AvailableContentTypes;

SPContentTypeCollection usedContentTypes = web.Lists[pageLib].ContentTypes;

foreach

(SPContentType contentType in allContentTypes)

{

if (contentType.Hidden==false && contentType.Group.ToLower().StartsWith("Mygroupname ") == true)

//if the content type does not yet exist in the library add it:

{

if (usedContentTypes[contentType.Name] == null)

{

web.Lists[pageLib].ContentTypes.Add(contentType);

}

}

}

That’s it for me!

抱歉!评论已关闭.