Section 3.2. Creating Custom Site Templates


3.2. Creating Custom Site Templates

To create a custom site template:

  1. Create a new site based on one of the predefined site templates.

  2. Modify the site.

  3. Save the site as a template.

For example, to extend the standard Team Site template to include a Picture Library:

  1. Create a new site based on the Team Site template. Choose Create Web Pages Sites and Workspaces, enter a title and address, and then click Create.

  2. Create Picture Library Picture Library, enter a library name , and then click Create.
  3. Go to Site Administration Save site as template. Figure 3-2 illustrates the results.
  4. SharePoint saves the site as a template file and adds it to the Site Template Gallery list.

animal 3-2. Saving a modified site as a new, custom template

Custom templates added to the Site Template Gallery appear in the templates list when you create a new site, as shown in Figure 3-3.

3.2.1. Viewing, Editing, and Deleting Template Files

The custom template file ( .stp ) in Figure 3-2 is actually a compressed cabinet file containing an XML template description. To see the contents of the template file:

  1. Choose Site Settings Go to Site Administration Manage site template gallery. SharePoint displays a list of the custom templates.

  2. Save the file to disk on your client computer.

    animal 3-3. The custom template automatically appears when creating new sites

  3. Rename the downloaded file to have the .cab file extension.

  4. Open the file using Extract, WinZip, or another file compression utility and extract the file manifest.xml .

  5. Open manifest.xml using FrontPage, WordPad or an XML editor (not Notepad; manifest.xml doesn't include whitespace, so you won't be able to decipher it).

The elements in manifest.xml , like all XML elements, are case-sensitive. Errors in either the element names or nesting will prevent the template from working.


The following XML fragment shows the details portion of the manifest.xml file for the custom template created in Figure 3-2:

 <?xml version="1.0" encoding="UTF-8" ?>    <Web Url="http://localhost/ModifiedTeamSite">        <MetaInfo>        ...        </MetaInfo>        <Details>            <TemplateDescription>Demo site template to show how easy it is to create a              new template based on an existing one.              </TemplateDescription>            <TemplateTitle>Team Site with Picture Library</TemplateTitle>            <Language>1033</Language>            <TemplateID>1</TemplateID>            <Configuration>0</Configuration>            <Title>Modified Team Site Template</Title>            <Description></Description>            <CalendarType>1</CalendarType>            <AlternateCSS></AlternateCSS>            <CustomJSUrl></CustomJSUrl>            <AlternateHeader></AlternateHeader>            <Subweb>1</Subweb>            <Locale>1033</Locale>            <Collation>25</Collation>            <TimeZone>13</TimeZone>        </Details>        ...    </Web> 

To make changes to a custom template directly:

  1. Edit manifest.xml . You can find reference information about the elements in the SharePoint SDK Help file ( spptsdk.chm ).

  2. Package the changed file using CabArc.exe . For example, the following command line packages changes as TeamWithPics2.stp .

     CabArc n TeamWithPics2.stp manifest.xml 

  3. Upload the packaged file to SharePoint from the Template Gallery. SharePoint adds the new template and displays its description in the site template gallery, as shown in Figure 3-4.

    Go to http://msdn.microsoft.com/library/en-us/dncabsdk/html/cabdl.asp to find CabArc .


animal 3-4. Uploading a new site template

To delete a template from the gallery, click the Edit icon next to the template name and then choose Delete from the template's description page. Deleting a custom site template doesn't affect existing sites based on that template.

3.2.2. Replacing a Predefined Template

It's very difficult to modify the predefined templates, and in fact Microsoft recommends that you avoid doing so, since upgrading to a new release of SharePoint would overwrite your changes and possibly break sites based on those templates.

It's simpler and safer to create a new, custom template with the same name, and then hide the predefined templatein effect replacing the predefined template with your own. To replace a predefined template with a custom template:

  1. Create a new, custom template with the same title as the template you want to replace.

  2. On the SharePoint server, edit the WebTemp.xml configuration file to hide the predefined template.

  3. Stop and restart IIS to refresh SharePoint's template list. To stop and restart IIS, run iisreset.exe on the SharePoint server.

The WebTemp.xml file is found in the C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\TEMPLATE\1033\XML folder of the SharePoint server. To hide a template, change the Hidden attribute to trUE , as shown here in bold :

 <Templates xmlns:ows="Microsoft SharePoint">     <Template Name="STS"     ID="1">        <Configuration ID="0" Title="Team Site"  Hidden="TRUE"  ImageUrl="/_layouts/images/    stsprev.png" Description="This template creates a site for teams to create, organize,    and share information quickly and easily. It includes a Document Library, and basic    lists such as Announcements, Events, Contacts, and Quick Links."></Configuration>    ...    </Template>    ...    </Templates> 

After you restart IIS, your custom template appears in the template list, as shown in Figure 3-3, and the built-in template doesn't. SharePoint always displays the built-in templates before the custom templates, so the order of the list is changed.

3.2.3. Adding Pages

When you create a new site template based on an existing site, SharePoint includes in the new site template any pages you added in these circumstances:

  • You created the pages with FrontPage. Pages added to a site through FrontPage are automatically included in the custom template.

  • You created the pages through SharePoint and you selected the Include content option when you created the template (Figure 3-2). Pages created through SharePoint are added to a library in the site and are treated as content.

Including content with the template copies the contents of all the site's lists into the new template; so if you've stored custom pages in the Shared Documents list, they will be included in any new site based on the custom template.

You can't selectively include some lists and exclude others. When including content in a template, create the template from a clean "base" site that contains only the content you want to copy into each new site.

You usually won't want to include lists that represent live data in a template. For example, including Contacts data in a template creates a new copy of Contacts each time a site is created from the template. If all of your sites share a common set of Contacts, you'll want those sites to link to the same data source rather than having to maintain multiple copies of the data.

3.2.4. Changing the Built-in Pages

Changes made to built-in pages, such as the home page ( default.aspx ), are copied to the new template when you create a new template based on an existing site. If you download the template file and open it with a cab-file viewer, such as WinZip, you can see the changes that the template includes, as shown in Figure 3-5.

The generated file names in the template file are mapped to the web-site file names through manifest.xml . For example, the d1000000.000 file displayed in Figure 3-5 maps to default.aspx, as shown by this snippet from manifest.xml :

 <File Name="default.aspx" Src="d1000000.000">     <MetaInfo>     ...     </MetaInfo>     </File> 



Essential SharePoint
Essential SharePoint 2007: A Practical Guide for Users, Administrators and Developers
ISBN: 0596514077
EAN: 2147483647
Year: 2005
Pages: 153
Authors: Jeff Webb

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net