Question
I want to select which template to use when a topic is created based on the topic's name, instead of always using
WebTopicEditTemplate. I've read
FormsAndTemplates, which I think is talking about something similar, but it didn't really help. When a user clicks a ? or enters a name in the Go box for a non-existent topic, I want the template to be chosen based not on the web but rather on simple matches on the pattern name. For instance, suppose I wanted one default text for topics that end in "News", another for topics that end in "Links", and
WebTopicEditTemplate for all others. How might I accomplish this?
- TWiki version: Dec 2001
- Web server:
- Server OS:
- Web browser:
- Client OS:
--
MitchellModel - 07 Nov 2002
Answer
Not an answer ready to use, but here we go. This is not in the TWiki core and probably cannot be solved easily with a Plugin. However you could patch the
edit script, fill in the blanks in red:
if( $templateTopic ) {
if( $templateTopic =~ /^(.+)\.(.+)$/ ) {
# is "Webname.SomeTopic"
$templateWeb = $1;
$templateTopic = $2;
}
( $meta, $text ) = &TWiki::Store::readTopic( $templateWeb, $templateTopic );
} else {
# add code here for conditional template handling
}
if( ! $text ) {
( $meta, $text ) = &TWiki::Store::readTemplateTopic( "WebTopicEditTemplate" );
}
--
PeterThoeny - 09 Nov 2002
Good enough. Thanks. As a highly technical and experienced Computer Scientist (including other Wiki implementations) I greatly appreciate answers like this. I have to resist the temptation to preface every question with the clarification that what I'm looking for is a way to accomplish what I want using, in priority order:
- an existing feature
- user-accessible customization facilities (e.g. TWiki variables, template pages, etc.)
- maintainer-accessible customization (e.g.,
TWiki.cfg, .tmpl templates, etc.)
- mature Wiki code patches
- quick & dirty suggestions for TWiki code patches
Now that I've said that, maybe I should move this comment to someplace more visible. Do you think that's a good idea? Seems to me these are widely shared priorities, that not everyone answering questions will think this way, and that these are sufficiently stable that maybe answers should always be marked with a tag showing which category they fall into (which would save a lot of qualifying text people end up writing). Or maybe the first step should be into a discussion somewhere, but I'm having trouble thinking of where to put it. I think you should decide, Peter.
--
MitchellModel - 09 Nov 2002
The Codev web is the place to ask for enhancements and contribute code! There was some dicussion on selectable templates, search (and link to) topics in the Codev web.
--
PeterThoeny - 09 Nov 2002