Summary: How to create a number of pages for a new group automatically
Version: 2006-08-05
Prerequisites: pmwiki 2.1
Status: stable
Maintainer: Petko

Questions answered by this recipe

How can I have a number of pages created automatically for a new group?


Here's a brief recipe that will create HomePage, GroupHeader, and GroupFooter automatically if they don't exist when a page is created in a group:

function AutoGroupPages($pagename, &$page, &$new) {
     global $IsPagePosted, $GroupPagesFmt;
     if (!$IsPagePosted) return;
     SDV($AutoGroupPagesFmt, array(
       '{$Group}.HomePage' => 'Templates.HomePage',
       '{$Group}.GroupHeader' => 'Templates.GroupHeader',
       '{$Group}.GroupFooter' => 'Templates.GroupFooter'));

     foreach($AutoGroupPagesFmt as $n => $t) {
       $n = FmtPageName($n, $pagename);
       $t = FmtPageName($t, $pagename);
       if (!PageExists($n) && $n != $pagename) {
         WritePage($n, ReadPage($t));

   $EditFunctions[] = 'AutoGroupPages';

The last line adds the function to the $EditFunctions array, which results in it getting executed whenever a page edit takes place, meaning that by editing a new page for a new group and saving it, the additional pages specified in the $AutoGroupPagesFmt array will be created too.

$AutoGroupPagesFmt can be defined with different pages prior of including the function.


The function is declared and used in newgroupbox.phpΔ. If you wish to use NewGroupBox and also have the function available generally to be used when editing a new page for a new group, then you should only add to config.php:

$EditFunctions[] = 'AutoGroupPages';

Automatic creation of Uploads Directory

If you need to have a group uploads directory created automatically, when a first page in a new group is created, you can add the following to local/config.php:

function AutoCreateUploadDirectory($pagename, &$page, &$new) {
 global $IsPagePosted, $UploadFileFmt;

 if (!$IsPagePosted) return;
 $uploaddir = FmtPageName($UploadFileFmt, $pagename);

$EditFunctions[] = 'AutoCreateUploadDirectory';

Note that normally PmWiki manages fine to create uploads directories when the need (i.e. upload) arises.

Release Notes

  • 2006-08-05: first release as published by Pm on the pmwiki-user list.

If the recipe has multiple releases, then release notes can be placed here. Note that it's often easier for people to work with "release dates" instead of "version numbers".

  • 2007-05-18: Fixed problem with clobbering pagename. That is, if you created an initial group page that was the name of one of the pages created by AutoGroupPages(), then it would overwrite the page. BenWilson May 18, 2007, at 09:47 AM

See Also




See discussion at AutoGroupPages-Talk

User notes +1: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.