The answer to your first question depends on whether you mean application pages or content pages. They each have their advantages: application pages are good in that they can run custom server-side code, and content pages are nice because (for example) they can be customized by users, but by default are restricted in what kind of code can be run.
For a pretty good discussion on the differences between the two types in capabilities and restrictions, check out the Windows SharePoint Services SDK and look at the topics called "Application _layouts page type" and "Content page type."
As for stapling, it's pretty easy and more flexible than adding new features to a site definition's onet.xml file. This article seems a pretty good overview of the alternatives. You might want to make a copy of the blank site definition, rename it, and then use that one in your work, though.
Features with content pages
You'll need three types of things for this:
- A feature.xml file -- just the boilerplate stuff that refers to the element manifest.
- A page template -- this could be the entire aspx page itself, or it could be (for example) a shell of a web part page with
WebPartZones
defined but no actual web parts (yet).
- The element manifest file which refers to your page templates and defines any web parts that should be provisioned as part of activation of your feature.
Your feature's folder structure would look something like this:
12
+-- TEMPLATES
+-- FEATURES
+-- YourFeature
+-- PageTemplates
| +-- Page.aspx (simple aspx page)
| +-- WebPartPage.aspx (still simple, but with WebPartZones)
+-- feature.xml
+-- elements.xml
Feature.xml:
<Feature
Id="CFF117BC-9685-4a7b-88D0-523D9DAD21F0"
Title="Custom Pages Feature"
Scope="Web"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="elements.xml"/>
</ElementManifests>
</Feature>
Elements.xml
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Path="PageTemplates" Url="Pages" >
<File Url="Page.aspx" Type="Ghostable" />
<File Url="WebPartPage.aspx" Name="WebPartPage.aspx" Type="Ghostable" >
<AllUsersWebPart WebPartZoneID="Left" WebPartOrder="0">
<![CDATA[
<WebPart xmlns="http://schemas.microsoft.com/WebPart/v2"
xmlns:cewp="http://schemas.microsoft.com/WebPart/v2/ContentEditor">
<Assembly>Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
<TypeName>Microsoft.SharePoint.WebPartPages.ContentEditorWebPart</TypeName>
<Title>Some content that you want to provision with the feature</Title>
<FrameType>TitleBarOnly</FrameType>
<cewp:Content>
Hello world.
</cewp:Content>
</WebPart>
]]>
</AllUsersWebPart>
</File>
</Module>
</Elements>
Page.aspx
<%@ Page MasterPageFile="~masterurl/default.master"
meta:progid="SharePoint.WebPartPage.Document" %>
<asp:Content runat="server" ContentPlaceHolderID="PlaceHolderMain">
Hello World
</asp:Content>
WebPartPage.aspx
<%@ Page Language="C#" MasterPageFile="~masterurl/default.master" Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage,Microsoft.SharePoint,Version=12.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" meta:progid="SharePoint.WebPartPage.Document" %>
<%@ Register Tagprefix="WebPartPages"
Namespace="Microsoft.SharePoint.WebPartPages"
Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<asp:Content ID="main" runat="server" ContentPlaceHolderID="PlaceHolderMain" >
<table width="100%">
<tr>
<td valign="top" style="width:50%">
<WebPartPages:WebPartZone ID="Left" runat="server"
FrameType="TitleBarOnly" Title="Left Web Part Zone" />
</td>
<td valign="top" style="width:50%">
<WebPartPages:WebPartZone ID="Right" runat="server"
FrameType="TitleBarOnly" Title="Right Web Part Zone" />
</td>
</tr>
</table>
</asp:Content>
If you configure your feature in that way, you should be able to deploy site content pages within that structure.
Also, I highly recommend Ted Pattison's Inside Windows SharePoint Services book. It covers this topic in much detail, including the important security aspects of site content pages. It's easily worth the purchase price.
The easiest way is to make use of designer to create the code for you...
- Create a page and open it advanced mode in SharePoint Designer.
- Add the required webpart into the webpart zone. This will create the
required html.
- Copy it and remove the g_ from the ID value.
- Use this code in your page layout.
Ps: Id the WebPart button is disabled in the SharePoint designer ribbon, just save the page. This will enable it.
The code that is generated by designer when I added Content Editor Webpart and Script Editor webpart is given below.
<WebPartPages:ContentEditorWebPart webpart="true" runat="server" __WebPartId="{BA190D08-907A-4F94-B8F0-C3966A61E601}">
<WebPart xmlns="http://schemas.microsoft.com/WebPart/v2">
<Title>$Resources:core,ContentEditorWebPartTitle;</Title>
<Description>$Resources:core,ContentEditorWebPartDescription;</Description>
<PartImageLarge>/_layouts/15/images/mscontl.gif</PartImageLarge>
<PartOrder>4</PartOrder>
<ID>ba190d08_907a_4f94_b8f0_c3966a61e601</ID>
</WebPart>
</WebPartPages:ContentEditorWebPart>
<WebPartPages:ScriptEditorWebPart runat="server" ChromeType="None" Description="$Resources:core,ScriptEditorWebPartDescription;"
ImportErrorMessage="$Resources:core,ImportErrorMessage;" Title="$Resources:core,ScriptEditorWebPartTitle;"
__MarkupType="vsattributemarkup" __WebPartId="{1861cebe-9134-4645-8500-13ce8817d416}" WebPart="true"
__designer:IsClosed="false" partorder="6" id="1861cebe_9134_4645_8500_13ce8817d416">
</WebPartPages:ScriptEditorWebPart>
Best Answer
You can provision the page in ONET.XML.
First add a web part page template to your site definition.
Then provision an instance of the page (with the web parted added) in your ONET.XML.
This stuff is described fully in Ted Pattison's book Inside Windows SharePoint Services 3.0
default.aspx
ONET.xml snippet