EditTemplates-Talk

Summary: Talk page for EditTemplates.
Maintainer: Petko
Users: +7 (View / Edit)

This space is for User-contributed commentary and notes. Please include your name and a date along with your comment.

Order of $EditTemplatesFmt

How does the order of $EditTemplatesFmt declaration affect the template page delivered? e.g.

  $EditTemplatesFmt[] = 'Trips.DayTemplate  name=Trips.*day?,Trips.*day??';
  $EditTemplatesFmt[] = 'Trips.MapsTemplate name=Trips.*maps,Trips.*maps';
  $EditTemplatesFmt = array('$Group.Template', '$DefaultGroup.Template'); 

When a page Trips.DestinationDay01 is created Trips.Template is used, rather than the desired Trips.DayTemplate

simon

The first page that matches, and that has some text content, will be used. However here, on the 3rd line you are redefining the whole array so only these last 2 templates are available. Instead, you should do something like (below).

## Either:
$EditTemplatesFmt[] = 'Trips.DayTemplate  name=Trips.*day?,Trips.*day??';
$EditTemplatesFmt[] = 'Trips.MapsTemplate name=Trips.*maps,Trips.*maps';
$EditTemplatesFmt[] = '$Group.Template';
$EditTemplatesFmt[] = '$DefaultGroup.Template';

## Or:
$EditTemplatesFmt = array(
  'Trips.DayTemplate  name=Trips.*day?,Trips.*day??', 
  'Trips.MapsTemplate name=Trips.*maps,Trips.*maps',
  '$Group.Template', '$DefaultGroup.Template'
);

The first one may be better if you add templates from multiple local configuration files (as opposed to redefining them). --Petko


Older discussions

On pmwiki.org this recipe has been enabled for the Cookbook (local/Cookbook.php) as follows:

$EditTemplatesFmt = 'Cookbook.Template';

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 actual setting on pmwiki.org is more complex, with *-Users and *-Talk pages using Cookbook.Template-Users and Cookbook.Template-Talk respectively:

  if (preg_match('/-Users$/', $pagename)) $EditTemplatesFmt = 'Cookbook.Template-Users';
  elseif (preg_match('/-Talk$/', $pagename)) $EditTemplatesFmt = 'Cookbook.Template-Talk';
  else $EditTemplatesFmt = 'Cookbook.Template';

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';

In order to easily duplicate existing pages, I find this code in *.GroupFooter very useful:

(:if auth edit {$Group}.ImaginaryNewPage:)

----

(:input form {$ScriptUrl} get:)
(:input hidden action edit:)
(:input hidden template {*$FullName}:)
New page based on current: (:input text pagename "{$Group}." size=32:)
(:input submit value="Create":)
(:input end:)
(:ifend:)

New page based on current:

In your SideBar, use instead (experimental):

(:if auth edit {*$Group}.ImaginaryNewPage:)
----
(:input form {$ScriptUrl} get:)
(:input hidden action edit:)
(:input hidden template {*$FullName}:)
New page based on current: (:input text pagename "{*$Group}." size=32:)
(:input submit value="Create":)
(:input end:)
(:ifend:)

StefCT, 2013-12-26


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

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.

I have used ->$EditTemplatesFmt = 'Cookbook.Template'; and ->$EditTemplatesFmt = '{$Group}.Template'; however with the first one ALL (even in different groups!) of my newly created wikipages included the text from my template and with the latter nothing appeared from my template. Am I doing something wrong? Additionally, I used

(:input form {$ScriptUrl}:)(:input hidden action edit:)
(:input hidden template LocalRestaurants.RestaurantName:)
Please enter new page title: (:input text pagename size=32:)
(:input submit create "Create!":)
(:input end:)

Please enter new page title:


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 ->$EditTemplatesFmt = '{$Group}.Template'; you must put that information (verbatum) in your local config and PMWiki will understand what to do next. I was putting LocalRestaurants.Template, instead it was $Group.Template. Good luck to all in working in this program! Thanks, Chris August 19, 2008

Talk page for the EditTemplates recipe (users).