|
Cookbook /
EditTemplatesSummary: Specify a wiki page or pages to use as a template when a new page is created.
Status: Stable
Prerequisites: pmwiki-2.0.0
Maintainer: Pm
Categories: Administration Editing
DescriptionThe $EditTemplatesFmt = 'Cookbook.Template';
will say to use the page Cookbook.Template as the template for all new pages. $EditTemplatesFmt = '{$Group}.Template';
says to use 'Template' within the current group as the template for new pages. Another possibility is $EditTemplatesFmt = '{$SiteGroup}.{$Name}Template';
which looks in the Site group for a template matching the name of the page being created. For example, the above would use "Site.HomePageTemplate" (if it exists) anytime an author creates a page named "HomePage" (in any group). An administrator can also specify an array of templates, in which case the first template found is chosen:
# use 'Template' in the current group if it exists, or the default group if it exists,
# otherwise use 'Main.MasterTemplate'
$EditTemplatesFmt = array('{$Group}.Template','{$DefaultGroup}.Template','Main.MasterTemplate');
One-Shot TemplatesIf you wish to create a new page based on the contents of an older page, without going through the effort to set it up as a template, then you can simply add the template= parameter to the end of the URL, like this: [[SomeGroup.NewPage?action=edit?template=OldGroup.OldPage]]
which will produce a link that, when clicked on, will open the NewPage using the contents of OldPage as the default. Single Page TemplatesIt is possible to modify a single page so that all links from it will use a common template. To modify the page SomeGroup.SomePage so all of the links within it will use the file SomeGroup.SomeTemplate as the edit template, create a file in the local directory named SomeGroup.SomePage.php containing the following php code: <? $LinkPageCreateFmt = "<a class='createlinktext' href='\$PageUrl?action=edit&template=SomeGroup.SomeTemplate'>\$LinkText</a> <a class='createlink' href='\$PageUrl?action=edit&template=SomeGroup.SomeTemplate'>?</a>"; ?> This changes the "edit new page" links in SomeGroup.SomePage to automatically include the template= parameter. The Template ShuffleIt is also possible to use different templates in different sections of a page by making use of PmWiki's Markup() function to create a new directive, (:edittemplate:), which sets the template of all links which follow it. For example, assume you are setting up page with two groups of links, one to pages about movies, and one to pages about TV shows, and you wish those links to use edit templates Main.MovieTemplate and Main.TVTemplate, respectively. By placing (:edittemplate Main.MovieTemplate:) at the start of the movie links, and then placing (:edittemplate Main.TVTemplate:) at the start of the TV show links, each group will be set up to use the appropriate templates. To make enable this capability, add the following to local/config.php:
# change the link format for creating new pages
$LinkPageCreateFmt = "<a class='createlinktext'
href='\$PageUrl?action=edit\$LinkTemplate'>\$LinkText</a>
<a class='createlink' href='\$PageUrl?action=edit\$LinkTemplate'>?</a>";
# default is no template
$FmtV['$LinkTemplate'] = '';
# the (:edittemplate Group.PageName:) markup causes any create page
# links that follow to use Group.PageName as the template
Markup('edittemplate', 'directives',
'/\\(:edittemplate(\\s+(\\S+))?\\s*:\\)/e',
"PZZ(\$GLOBALS['FmtV']['\$LinkTemplate'] = '$2' ? '&template=$2' : '')");
If after a specific section you want to return to the default new page behavior, simply insert (:edittemplate:) with no page reference, and the previously set template will be cleared. Simple form for creating new pagesThis is a simple form for creating a page using a template.
When the editor fills the new page title and presses "Create!", he sees a new page where the textarea is not empty but filled with the content of the page MyTemplateGroup.MyTemplate. See also the more advanced recipes New page box plus and New group box. Notes and CommentsOn pmwiki.org this recipe has been enabled for the Cookbook (local/Cookbook.php) as follows: $EditTemplatesFmt = 'Cookbook.Templates';
Thus any new pages created in the cookbook are pre-populated with the contents of Cookbook.Template. You can try it via Cookbook.SampleNewPage?action=edit (delete SampleNewPage if it already exists to see the template at work). The following code in Board.php allows me to use a template only for those pages in the Board group whose title matches a certain pattern:
$minutes_pagename_pattern = "Board.Minutes[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}";
if ("edit" == $action and ereg($minutes_pagename_pattern, $pagename))
{
$EditTemplatesFmt = "Board.MinutesTemplate";
}
In my V1 code I was able to use $Group instead of Board, but that doesn't seem to work anymore. Why not? Also, there's probably a better way to do this in V2, so I'd welcome suggestions. shi Well, since you're placing the above in Board.php, you don't really need to match the group anyway (the group is known to be "Board"). So try this: $minutes_pattern = '/\\.Minutes\\d{4}-\\d\\d-\\d\\d$/';
if ($action == 'edit' && preg_match($minutes_pattern, $pagename))
$EditTemplatesFmt = 'Board.MinutesTemplate';
Also known as (by me anyway) page templates, prefilled pages, prefill edit box - maybe now my searches will find this page. NeilHerber March 23, 2006, at 12:24 PM See Also
Contributors
QUESTIONS:
Ok, so my name seems to be popping up more frequently here. I have tried 2 things (I'm using PMWiki build 2.65 (haven't upgraded yet to .68) and I'm having an issue with this command, which I need heavily to work.
and while this worked it started creating new groups and pages, however my template was included. What that meant for me practically is that I was creating a LocalRestaurants group and was including the restaurants name (LocalRestaurants/RestaurantName), however what happened was that something like (RestaurantName/RestaurantName) was created. Please help the newb here. Thanks, Chris August 18, 2008 Could the recipe http://www.pmwiki.org/wiki/Cookbook/NewGroupWarning be creating a conflict? -Edit, ok, so I don't give up with no answer. I proceeded to find out what I was doing wrong and at the same time answered my own question, thankfully. The markup for the first part was really easy, I was just reading too much into the directions. So, for all you newbies out there, when it says -> |