[Pmwiki-users] adding page templates
Knut Alboldt
mailing
Fri Oct 22 16:25:11 CDT 2004
tried to implement page edit templates (different according to group /
pagenames). Thought to get the infos from PITs-implementation.
First I check the new pagename with a matchcode for an corresponding template.
If found then I read in the templatepage, change some strings by variable
contents and change action to "edit".
The new page is presented in editmode with the text from the template page.
but: when I save, I save only the original template text, not the edited.
All author input is lost.
any ideas, why (please help) ?
Knut
PS: the script snipplet:
--------------------------------------
# ok, can be done better with an keyed array and a preg_match ...
if (preg_match('/^PITS\.\d/',$pagename))
{ $PageTemplate = 'PITS.Template'; }
elseif (preg_match('/^Configurationmanagement\.HWPC.*/',$pagename))
{ $PageTemplate = 'Configurationmanagement.TemplateHWPC'; }
elseif (preg_match('/^Configurationmanagement\.HWDrucker.*/',$pagename))
{ $PageTemplate = 'Configurationmanagement.TemplateHWDrucker'; }
....
# actually the following part is in an included script
SDV($PageTemplate,"");
if ($action=='edit')
{
if (!PageExists($pagename)) { ReadTemplatePage($PageTemplate); }
}
function ReadTemplatePage($templatepage)
{
global $Now, $Author;
if ($templatepage === "") { return; }
if (PageExists($templatepage))
{
$page = ReadPage($templatepage); # read the template page
$changes = array('/NOW\(\)/' => strftime('%Y/%m/%d %H:%M',$Now),
'/JETZT\(\)/' => strftime('%d.%m.%Y %H:%M',$Now),
'/AUTOR\(\)/' => $Author,
'/AUTHOR\(\)/' => $Author);
$_POST['text'] =
preg_replace(array_keys($changes),array_values($changes),$page['text']);
}
}
More information about the pmwiki-users
mailing list