This question about Developing extensions (plugins skins etc.): Answered

Adding support for a variable to plugin code

TWiki has a plugin called ChildTopicTemplatePlugin.

This plugin allows you to specify in a topic what template should be used when a child topic is created via [clicking a WikiWord in the topic]. 

That second sentence bothers me a bit, as I think it should be an option, not a feature. But I digress.

I want to see this plugin working in Foswiki and I'm willing to port it as necessary and test it. However, it needs one additional feature for me to be willing to even use it. I could use some help understanding how best to implement this feature.,

At present, the plugin works this way:

  • Write the command %CHILDTOPICTEMPLATE{ "NameOfTopicTemplate" }% anywhere in your text.
  • All subsequent red-linked WikiWords will be created using the specified topic template.
  • Use %CHILDTOPICTEMPLATE{}% to remove the child topic template.
  • A topic can contain any number of CHILDTOPICTEMPLATE commands.

That's a novel feature, but not really helpful in a wiki application. Writing %CHILDTOPICTEMPLATE{...}% anywhere in the text makes it visible (editable) to users and therefore potentially undependable if used in an app.

I want to add support for a variable that will set the desired child topic template for the entire page, eg.
   Set USECHILDTOPICTEMPLATE = MyApplicationTemplate

This could then be set in the Settings of the original template, copied every time, and be far less likely to be touched by a user.

I looked at the code. I'm confused.

I never really got into OOPerl and I work best from examples I can modify and extend. It would help if I had an example of a plugin that uses a configuration variable in this way.


-- VickiBrown - 03 Apr 2017

I am not sure it needs a plugin as we have the NEWLINKFORMAT preference. Maybe the following works: Imagine something like this in your Web/SitePreferences:

   * Set NEWLINKFORMAT = <a href="%SCRIPTURLPATH{"edit"}%/$web/$topic?topicparent=%BASEWEB%.%BASETOPIC%&templatetopic=%NEWLINKTEMPLATE{default=""}%" rel="nofollow" title="%MAKETEXT{"Create this topic"}%"  class="foswikiNewLink">$text</a>

Then you could set NEWLINKTEMPLATE as needed pointing to the template you actually need.

-- MichaelDaum - 03 Apr 2017

While setting NEWLINKTEMPLATE sounds nicely convenient, the syntax for the NEWLINKFORMAT preference makes me shudder. wink

-- VickiBrown - 06 Apr 2017

Pasting GeorgeClark's IRC suggestion here so as not to lose it:

But as far as accessing a preference,  The block of code  foreach( split /%CHILDTOPICTEMPLATE ... if .... {   }      would be changed.  Just use Foswiki::Func::getPreferencesValue( 'USECHILDTOPICTEMPLATE' ) ...  That would return the preference to then test if it is set and alter the html.

-- VickiBrown - 06 Apr 2017

QuestionForm edit

Subject Developing extensions (plugins skins etc.)
Version Foswiki 2.1.3
Status Answered
Related Topics
Topic revision: r3 - 06 Apr 2017, VickiBrown
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy