This Plugin allows you to automatically create topics or attach files at topic save time. This is typically used by Foswiki applications to create a set of template based topics.
TOPICCREATE - Automatically Create a Set of Foswiki Topics
The %TOPICCREATE{}% macro is useful for creating topics based on templates
Example scenario: You have a notebook application where users can create new notebooks based on a notebook template topic. Each time a user creates a new notebook you would like to create a set of child topics, each based on a separate template.
Name of the template topic containing this use of TOPICCREATE
Any valid topic name (WikiWord)
recommended
<anything else>=""
Any other parameters are passed to a child topic to initialize any urlparams or set any form field values.
Any string
None
The action to create the Foswiki topic will not occur until one hits the Save Changes button in preview
The %TOPICCREATE{}% macro will be removed upon saving of the topic
Any attachments that are in the template will also be copied to the new topic
%TOPICCREATE% is recursive
Write %TOPICCREATE{ template="MyTemplate" topic="%TOPIC%MyNewTopicName" MyParameterName="MyParameterValue" Hello="Goodbye" }% to create a foswiki topic based on another topic MyTemplate with the name %TOPIC%MyNewTopicName. Any %URLPARAM{}% or any form field values with the name MyParameterName and Hello present in MyTemplate will be replaced with MyParameterValue and Goodbye.
To prevent the action from happening in your template topic you should either include the disable argument, or escape it: %TOPICCRE%NOP%ATE{...}%. The %NOP% gets removed when a topic gets instantiated based on a template.
TOPICATTACH - Automatically Copy Attachments to a Topic
Example scenario: You have a template topic and would like to attach a file whose content or name is determined by URL parameters at topic creation time. This is usually done for a topic that was just created via TOPICCREATE as described above.
Comment to appear for the attachment within this topic, replacing the comment that was in the fromtopic
a one line string
{omit parameter if no change desired}
disable=""
Name of the template topic containing this use of TOPICATTACH
Any valid topic name
recommended
fromfile=""
The attachment to copy from
Any attached file from fromtopic
(required)
fromtopic=""
Topic (or Web.Topic) that contains the attachment
Any valid Foswiki topic
(required)
name=""
Name to appear for the attachment within this topic, replacing the name that was in the fromtopic
a one line string
{omit parameter if no change desired}
Write %TOPICATTACH{ fromtopic="SourceTopic" fromfile="Sample.jpg" name="Snoopy.jpg" disable="..."}% to attach Sample.jpg from topic SourceTopic as Snoopy.jpg
The parameter value comment is used to change the comment (description) that shows for the topic in the table of attachments
The "hidden" attribute of the topic is removed: the attachment can be hidden in the fromtopic if desired
The fromtopic can specify a different web if desired. For example Foswiki.SomeTemplate would be valid as a fromtopic
To prevent the action from happening in your template topic you must provide the disable parameter with the topic name containing the %TOPICATTACH%.
Notes
Since version 1.7 of this plugin, you can pass a value to a form field on the topic by adding a parameter with the same name as the field.
Before version 1.4 of this plugin, the extra TOPICCREATE parameters were passed in using a special parameters attribute, as follows:
This is now deprecated. Instead, extra parameters are automatically passed through, as documented above.
The TOPICATTACH must be in the 'top level' topic being saved by a TOPICCREATE. It can not be in a recursive/subordinate topic invoked by the TOPICCREATE
There is a half-baked %TOPICPATCH% implementation which requires completing, testing and documenting. You are more than welcome to implement this if you would find it useful.
Plugin Settings
Plugin settings are stored as preferences values. You can override the defaults for these preferences in SitePreferences, the WebPreferences topic of the current web, or in individual topics that use the plugin. Changing them here will have no effect! This allows you to upgrade the plugin without having to worry about losing your settings.
Debug plugin: (See output in the Foswiki debug log)
Set TOPICCREATEPLUGIN_DEBUG = 0
Installation Instructions
You do not need to install anything in the browser to use this extension. The following instructions are for the administrator who installs the extension on the server.
Open configure, and open the "Extensions" section. Use "Find More Extensions" to get a list of available extensions. Select "Install".
If you have any problems, or if the extension isn't available in configure, then you can still install manually from the command-line. See http://foswiki.org/Support/ManuallyInstallingExtensions for more help.
v1.0: Foswikitask:Item1262 - Ported to Foswiki and released as 1.0; Removed dependency on Unix utilities cp and mkdir, should now work on any OS that Foswiki does; Improved code to make it cleaner and use more of the official API; Removed deprecated API calls -- Foswiki:Main.AndrewJones
11686
TWikibug:Item2956 - Freeze TWikiRelease04x00 and copy it to new branch MAIN
10613
TWikibug:Item2473 - files in pub and data directories shouldn't be marked executable in svn (Ordnung muss sein)