|
Cookbook /
AutoGroupPagesSummary: How to create a number of pages for a new group automatically
Version: 2006-08-05
Prerequisites: pmwiki 2.1
Status: stable
Maintainer:
Categories: Editing, Administration
Questions answered by this recipeHow can I have a number of pages created automatically for a new group? DescriptionHere'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 $AutoGroupPagesFmt can be defined with different pages prior of including the function. NotesThe 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 DirectoryIf 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);
mkdirp($uploaddir);
}
$EditFunctions[] = 'AutoCreateUploadDirectory';
Note that normally PmWiki manages fine to create uploads directories when the need (i.e. upload) arises. Release Notes
CommentsThe syntax on this page for creating the pages looks like this:
{$Group}.GroupHeader' => 'Templates.GroupHeader'
And on the NewGroupBox recipe page like this:
'Templates.GroupHeader' => '{$Group}.GroupHeader',
Which way is it really? LasseS They are different! If you use NewPageBox you won't need AutoGroupPages. It is built in. But I reversed the page - template pairing, since it looked more natural to write Template => Page. Well maybe I should not have changed this, as it may be confusing! HansB
See AlsoContributors |