I (DerekLakin) have an implementation of this working now and I thought here was the best place to discuss it prior to its submission as a change packet Now submitted -- DerekLakin [13-Jan-2005].
Overview
The solution provides the option of specifying multiple templates per namespace by creating topics that begin with _Template, e.g. _TemplateMyFavouriteStyle. The solution modifies wikiedit.aspx so that all topics named in this way are displayed in drop-down list on the edit page with the name formatted to remove the _Template portion (see the image on the right).
The new wikiedit.aspx page simply checks all the topics in the current namespace looking for template topics and builds up a the list to display. If there aren't any then the 'Topic Templates' pane isn't shown. When you click on the accompanying button some client-side javascript is called to insert the template text in to the current topic.
The javascript to provide this is as follows:
function ChangeTemplate(selectId)
{
var templateCombo = document.getElementById(selectId);
if ((templateCombo) && (templateCombo.selectedIndex > -1))
{
var strInsertText = templateCombo.options[templateCombo.selectedIndex].value;
var objTextArea = document.forms['Form1'].Text1;
if (document.selection && document.selection.createRange)
{
objTextArea.focus();
var objSelectedTextRange = document.selection.createRange();
var strSelectedText = objSelectedTextRange.text;
objSelectedTextRange.text = strInsertText + strSelectedText;
}
else
{
objTextArea.value += strInsertText;
objTextArea.focus();
}
}
}
If I've missed something here then I'm open to modifications to improve this. As you can see the client-side combo is built up with the template content specified as the value for each item.
Default Templates
If you create a topic called _TemplateDefault in a namespace then this becomes the default template for the namespace. Creating a new topic in this namespace will have this content by default. If a default template has not been created then the FlexWiki default text is used.
Other Things To Note
I'm not sure why, but at the same time as I implemented all this I added the ability to receive a template via the request. So if template=_TemplateMyFavouriteStyle or whatever is specified in the Url then this is used as the content for a newly created topic. I still haven't thought of a situation where you could make use of this, but maybe someone else can.
To Do List
What I haven't done yet that I think probably should be implemented is to provide access to template defined in the default namespace to all namespaces. This would allow templates to be overriden or new templates defined in a new namespace whilst still retaining access to a default set of templates.
In order to do this I just need to extend the processing in the wikiedit.aspx codebehind so that the templates for the default namespace are added to the list as well as those for the current namespace (if we're not currently in the default namespace). I think probably the best solution is to prefix the default template names with an asterisk in the drop down list.
As always you're comments, feedback, suggestions, etc are welcome -- DerekLakin [14-Dec-2004]
I figured it out. There has to be at least one _Template. Then it appears automatically.
Derek Lakin is a C# .NET developer primarily focusing on Windows Forms development and a CoreDeveloper for FlexWiki. Currently employed by "Content Master":http://www.contentmaster.co.uk producing learning material, white papers, and presentations, primarily for "Microsoft":http://www.microsoft.com.
11/20/2007 3:40:12 AM - -90.206.52.15
<Summary of bug fix>Summary: Which version is required for this ChangeNote
4/3/2008 9:43:28 AM - -199.31.3.195
Create templates for new topics within a given namespace.
9/19/2008 4:11:54 PM - FLWCOM-jwdavidson
Indicates the bugs on the BugTracker that are related to this topic.
9/24/2008 4:56:58 PM - FLWCOM-jwdavidson
Which are the related Feature Requests
1/24/2008 2:03:32 PM - FLWCOM-jwdavidson
Derek Lakin is a C# .NET developer primarily focusing on Windows Forms development and a CoreDeveloper for FlexWiki. Currently employed by "Content Master":http://www.contentmaster.co.uk producing learning material, white papers, and presentations, primarily for "Microsoft":http://www.microsoft.com.
11/20/2007 3:40:12 AM - -90.206.52.15
Derek Lakin is a C# .NET developer primarily focusing on Windows Forms development and a CoreDeveloper for FlexWiki. Currently employed by "Content Master":http://www.contentmaster.co.uk producing learning material, white papers, and presentations, primarily for "Microsoft":http://www.microsoft.com.
11/20/2007 3:40:12 AM - -90.206.52.15
David Ornstein works at Microsoft. He is the primary original author and a key contributor to the software (FlexWiki) that makes this wiki run.
12/30/2005 5:33:26 PM - -208.54.15.129
The software running this site. -> jump to HomePage
10/22/2006 7:52:17 AM - -81.182.199.248
Derek Lakin is a C# .NET developer primarily focusing on Windows Forms development and a CoreDeveloper for FlexWiki. Currently employed by "Content Master":http://www.contentmaster.co.uk producing learning material, white papers, and presentations, primarily for "Microsoft":http://www.microsoft.com.
11/20/2007 3:40:12 AM - -90.206.52.15
The software running this site. -> jump to HomePage
10/22/2006 7:52:17 AM - -81.182.199.248
David Ornstein works at Microsoft. He is the primary original author and a key contributor to the software (FlexWiki) that makes this wiki run.
12/30/2005 5:33:26 PM - -208.54.15.129
The software running this site. -> jump to HomePage
10/22/2006 7:52:17 AM - -81.182.199.248
David Ornstein works at Microsoft. He is the primary original author and a key contributor to the software (FlexWiki) that makes this wiki run.
12/30/2005 5:33:26 PM - -208.54.15.129
Click to read this topic
9/8/2007 8:59:26 AM - -76.30.20.161
Click to read this topic
9/8/2007 8:59:26 AM - -76.30.20.161
Derek Lakin is a C# .NET developer primarily focusing on Windows Forms development and a CoreDeveloper for FlexWiki. Currently employed by "Content Master":http://www.contentmaster.co.uk producing learning material, white papers, and presentations, primarily for "Microsoft":http://www.microsoft.com.
11/20/2007 3:40:12 AM - -90.206.52.15
Click to read this topic
9/8/2007 8:59:26 AM - -76.30.20.161
Click to read this topic
9/8/2007 8:59:26 AM - -76.30.20.161
The software running this site. -> jump to HomePage
10/22/2006 7:52:17 AM - -81.182.199.248
David Ornstein works at Microsoft. He is the primary original author and a key contributor to the software (FlexWiki) that makes this wiki run.
12/30/2005 5:33:26 PM - -208.54.15.129
Derek Lakin is a C# .NET developer primarily focusing on Windows Forms development and a CoreDeveloper for FlexWiki. Currently employed by "Content Master":http://www.contentmaster.co.uk producing learning material, white papers, and presentations, primarily for "Microsoft":http://www.microsoft.com.
11/20/2007 3:40:12 AM - -90.206.52.15
Derek Lakin is a C# .NET developer primarily focusing on Windows Forms development and a CoreDeveloper for FlexWiki. Currently employed by "Content Master":http://www.contentmaster.co.uk producing learning material, white papers, and presentations, primarily for "Microsoft":http://www.microsoft.com.
11/20/2007 3:40:12 AM - -90.206.52.15
Click to read this topic
1/18/2005 1:41:13 AM - DerekLakin-62.189.22.124
David Ornstein works at Microsoft. He is the primary original author and a key contributor to the software (FlexWiki) that makes this wiki run.
12/30/2005 5:33:26 PM - -208.54.15.129
Click to read this topic
5/28/2007 2:34:12 PM - author unknown
Derek Lakin is a C# .NET developer primarily focusing on Windows Forms development and a CoreDeveloper for FlexWiki. Currently employed by "Content Master":http://www.contentmaster.co.uk producing learning material, white papers, and presentations, primarily for "Microsoft":http://www.microsoft.com.
11/20/2007 3:40:12 AM - -90.206.52.15
Click to read this topic
9/8/2007 8:59:26 AM - -76.30.20.161
Click to read this topic
5/28/2007 2:34:12 PM - author unknown
Click to read this topic
9/8/2007 8:59:26 AM - -76.30.20.161
Derek Lakin is a C# .NET developer primarily focusing on Windows Forms development and a CoreDeveloper for FlexWiki. Currently employed by "Content Master":http://www.contentmaster.co.uk producing learning material, white papers, and presentations, primarily for "Microsoft":http://www.microsoft.com.