Object reference not set to an instance of an object.
Object reference not set to an instance of an object.
Customizable Topic Templates
.
Owner
Summary
RequiredBuild
RelatedBugs
RelatedFeatureRequests

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.

DavidOrnstein
DerekLakin
I really like the sound of this and I think it's exactly what FlexWiki needs to help bring it to the 'wiki uneducated'. Presumably we'd then need some further changes to probably the edit page to allow the user to specify the topic name there?
Note
DavidOrnstein

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.

DavidOrnstein
Another way to do this would be to allow a multi-valued property in the ContentBaseDefinition. I'm not saying this would be better, but I observe that we may be developing two ways to do similar things -- well-known topic names in a namespace and properties in the ContentBaseDefinition. Not sure what this means yet or if it's good, bad or not important...
DerekLakin
The advantage of using template discovery rather than specification in the ContentBaseDefinition is that the wiki administrator doesn't need to maintain the ContentBaseDefinition to make templates available. I guess the advantage is that the wiki administrator has control over what becomes generally available to the public as a template. Maybe we (the FlexWiki community) need to discuss this a bit further.

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.

DavidOrnstein
DerekLakin
JonathanTappan
That sounds useful. How about a trigger based on the beginning of the topic name: If you create a new topic called ChangeNoteFooBar and have a template called _TemplateChangeNote then the edit window starts up with the contents of that template instead of the default template.
DerekLakin

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.

DavidOrnstein
DerekLakin
This brings back the point about the ContentBaseDefinition mentioned above with the added disadvantage that you can't edit the NamespaceMap as a wiki topic like you can the ContentBaseDefinition. To be honest this area was something I thought of afterwards, which is why it isn't implemented yet, so I'm still open to ways of providing the feature.

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]

Question

You seem to currently be using version 1.8.0.1673

FlexWiki 2.1.0.288

When I edit, I see the TopicTemplates box on the right.

I am using 1677, but get no TopicTemplates box. What am I missing?

Thanks, BradWhite

I figured it out. There has to be at least one _Template. Then it appears automatically.

Object reference not set to an instance of an object.