Per-Group and Per-Page Customizations in config.php

Summary: Place your per-group and per-page customizations in config.php rather than in separate PHP scripts.
Version: Still a draft
Prerequisites: PmWiki 2.x
Status: Quo
Categories: Administration

Questions answered by this recipe

How can I do per-group and per-page local customizations in config.php rather than the normal way using GroupName.php and GroupName.PageName.php.


You can do per-group and per-page local customizations in config.php. This can make keeping track of customizations easier because all local configuration happens in one file rather than several files.

You probably will want to place the Group- or page-specific customizations at the end (bottom) of your config.php local configuration file. If you do it in a farmconfig.php file, the lines should probably come after "@include_once('local/config.php');" so they will not interfere with other local customizations.

Getting the group and page name

First, you need to make sure the page name is resolved and optionally you can set variables to hold the group and/or page name(s).

$pagename = ResolvePageName($pagename);
$group = PageVar($pagename, '$Group');
$name = PageVar($pagename, '$Name');

Customization for a group

Now you can do customization for a group.

if ($group == 'SpecialGroup') {
  ## Your customization here

Don't execute that cookbook for that Group :

if ($group != 'SpecialGroup') {

Customization for a page

You can do customization for a page by page name (that is, customize all pages with a certain name that may exist in any group).

if ($name == 'Test') {
  ## Your customization here

You can also do fancier name-matching, of course. Here is an example that affects all pages, in any group, that have names that end in "-Talk":

if (preg_match('/-Talk$/', $name)) {
  ## Your customization here

Customization for a single page

If you want your customization to affect only one page, it's done with

if ($pagename == 'Main.WikiSandbox') {
  ## Your customization here

CSS Customizations

It's probably best to use /pub/css/GroupName.css to do per-group CSS styling, but you can also do it in ''config.php;'. Here, we make one group have a light-blue background color in the content area:

if ($group == 'SpecialGroup') {
  $HTMLStylesFmt['specialgroupbg'] = "
  #wikibody { background-color:#f7f7ff; } ";



See Also


User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.