|
PageTemplate<< Diff Access Level | Cookbook-V1 | Upload Groups >> Note: The recipes here are for PmWiki versions 0.6 and 1.0 only. For PmWiki 2.0 recipes, see Cookbook.
GoalFor some Wiki pages, like bug reports, it's good to define a standard structure of the page. Using a page template can help users follow the standard page structure for new pages without having to re-type the page structure or copy-and-paste from other pages. SolutionThe solution is particularly simple.
<?php
$FormTemplatePage = '$Group.Template';
if ($action=="edit") {
$formpage = ReadPage(FmtPageName($FormTemplatePage,$pagename));
$DefaultPageTextFmt = $formpage['text'];
}
?>
This sets the default page text for new pages to the text of your template page. When users click on a link to start a new page, the edit box will be filled up with the contents of the template page. DiscussionIf you decide to use a fixed name for the template page in all of your groups, you can include the above code in your Writing good templates is a dark art. It's good to use %%comment%% blocks to give instructions to editors on how to use the template and what kind of information should go where. See Also
History
Comments & Bugs
<?php
$SpecificTemplatePage1 = '$Group.TemplateOne';
$SpecificTemplatePage2 = '$Group.TemplateTwo';
$DefaultTemplatePage = '$Group.DefaultTemplate';
# match page names formatted like Minutes2003-12-03
$template1_pattern = "{$Group}/Minutes[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}";
# match page names formatted like Photos2002-02-03
$template2_pattern = "{$Group}/Photos[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}";
if ("edit" == $action)
{
if (ereg($template1_pattern, $pagename))
{
$formpage = ReadPage(FmtPageName($SpecificTemplatePage1, $pagename));
}
elseif (ereg($template2_pattern, $pagename))
{
$formpage = ReadPage(FmtPageName($SpecificTemplatePage2, $pagename));
}
else
{
$formpage = ReadPage(FmtPageName($DefaultTemplatePage, $pagename));
}
$DefaultPageTextFmt = $formpage['text'];
}
?>
Contributorspmwiki-2.2.0-beta68 -- Last modified by {{Ian MacGregor}}
|