Summary: Replace On Edit
Version: 1.2
Prerequisites: none
Status: Working
Maintainer: GNUZoo
Categories: Markup

NOTE: This recipe (below the examples) is not needed if you are using pmwiki-2.2.0-beta45 or later versions. Instead use $ROEPatterns (very similar to $ROSPatterns). See $ROEPatterns for comments/examples of how to use that variable.

Questions answered by this recipe

  • Is there a replace on edit like there is a replace on save?

This section is optional; use it to indicate the types of questions (if any) this recipe is intended to answer.


ROEPatterns (Replace On Edit) works just like ROSPatterns except that it is executed before a page is edited.

Can this page be refactored as an example page for ROEPatterns, similar to ROSPatterns? HansB May 06, 2007, at 05:24 AM

The $ROEPatterns are enabled by placing them in the local/config.php file.

$ROEPatterns ["text to search for"] = "text to replace with";

The "text to search for" is searched and replaced using the PHP preg_replace function, thus the pattern has to use the preg_replace syntax.

Recipe Example:

A config/php or recipe could setup a new action, then setup $ROEPatterns and then go to the editor

    if ($action == 'convert') {
        global $ROEPatterns;
        $ROEPatterns ['/\\|\\|/'] = '(:cell:)';
        # ... MORE $ROEPatterns could go here


Copy ReplaceOnEdit.phpΔ to your cookbook directory.

In your config.php enter:


or in your farmconfig.php enter:



This recipe is intended for wiki administrators. It could be useful for a recipe that might want to modify text on a page just before displaying it in the editor.

Release Notes

This program is free software.
You can redistribute it and/or modify it under
the terms of the GNU General Public License as
published by the Free Software Foundation either version 2 of the
License, or (at your option) any later version.

Copyright 2007

  • Version: 1.1 - added RecipeInfo
  • Version: 10 12 2006 05:40 am CST - Initial release


Usage of $ROEPatterns for pmwiki-2.2.0-beta45 and after

As of pmwiki-2.2.0-beta45 the recipe above became incorporated into the core as a $ROEPatterns array. Here are some comments and examples on how to use $ROEPatterns:

  • Typically one significant reason for $ROEPatterns is for template pages. You create the template with certain patterns and then when a new page is created from that template the $ROEPatterns are automatically substituted and your page has the desired values.
  • The difficulty with template substitutions is that they have a tendency to get substituted while you are editing the template page itself -- thus the search-pattern (in the KEY of $ROEPatterns) is never found when the new page is created because it was already substituted in the template page. Here's how to get around that in your config.php:
if (!in_array($pagename, array('GroupA.Template', 'GroupB.Template'))) {
   $ROEPatterns['/searchpat/'] = 'ReplaceString';

That way the $ROEPatterns are not "active" for the template pages themselves (assuming you have listed all your template pages in the array) and so you can place the search patterns in the template and they will not be replaced until a new page is created from the template.

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.