- September
- 27
- 2007
SharePoint Wiki: Create pages based on a template
Posted by mhofer1976
No Comments »
Creating Wiki-Pages from a Template
To make Wiki pages look uniform, it would be handy if there was always the same template used when the pages are created. Unfortunately, WSS 3.0/MOSS 2007 doesn't support this functionality (yet). The below paragraphs show the concept on how to achieve this functionality. Neither the code nor the configuration steps described are suitable for a production environment – they are just the proof-of-concept that it is possible. Adopt it freely!
The configuration part
1. Create a WIKI site
2. Create a Custom List called something like “Page Templates”
3. Add a custom column “Template” and make it multi-line rich-text including pictures etc.
4. Now create your HTML Template.
5. Copy your HTML (only the part inside the <body> of course) and add an entry in your custom list. In my example, the title is “Wikipedia” and in the “Template Column” switch to HTML view and paste your HTML Teplate
6. If your template needs a separate stylesheet, you must proceed like with any other stylesheet in MOSS (and make sure it doesn't interfere with the standard styles so your layout gets corrupted.):
a. Upload the style sheet to the appropriate location in the Styles Library
b. Add a link to the style-sheet to the master page (Example: <SharePoint:CssRegistration name="<% $SPUrl:~sitecollection/Style Library/wikipedia_common.css %>" runat="server"/>)
The development part
Before I show the development steps this warning: This is a quick'n'dirty approach in a development environment and you mustn't change standard MOSS-files! If you want to use this in a real environment, create a custom site definition where the Wiki Pages list doesn't point to _layouts/CreateWebPage.aspx but to your own page which is deployed with your custom site definition. However, the scope of this instruction is only to show how it is supposed to work. Please keep this also in mind when looking at the code!
1. Create a new class-library
2. Make sure it will be signed
3. Add two references:
a. Microsoft.SharePoint.dll (12ISAPI)
b. Microsoft.SharePoint.ApplicationPages.dll (12CONFIGBIN)
4. Create your class inheriting from CreateNewWeb as shown in the code example. I guess the code is self-speaking:
|
using System; namespace Mho.SharePoint.Trials public EnhancedCreateWebpage() { } protected override void OnPreRender(EventArgs e) this.FindRichTextControl(listFieldIterator); private void FindRichTextControl(Control control) } |
5. Compile and deploy to the GAC
6. <Warning! See above paragraph – this is not supported!>
a. Open the file “12TEMPLATELAYOUTSCreateWebPage.aspx” (a backup could maybe be handy.)
b. Change the header to point to your assembly:
<%@ Assembly Name="Mho.SharePoint.Trials, Version=1.0.0.0, Culture=neutral, PublicKeyToken=261ba54b9846991b"%>
c. Set the correct class to inherit from
<%@ Page Language="C#" Inherits="Mho.SharePoint.Trials.EnhancedCreateWebpage".
d. Add the name of the “ListFieldIterator” control you've used in the class code as its ID:
<SharePoint:ListFieldIterator ID="listFieldIterator".
7. Recycle the application pool and try it out.