Jump to main content Jump to doc navigation

Event: OnWebPagePrerender

Fired after a Resource is parsed, but before it is rendered.

Content Type headers have not yet been sent, nor has the output been flushed.

  • Service: 5 - Template Service Events
  • Group: None

Event Parameters



Description: Filter words from a document before it's displayed on the web System Events: OnWebPagePrerender

$words = array("snippet", "template"); // words to filter
$output = &$modx->resource->_output; // get a reference to the output
$output = str_replace($words,"<b>[filtered]</b>",$output);

Be careful if your OnWebPagePrerender plugin is a static element and it includes or requires files using relative paths. The plugin code executes from its cached file, e.g. core/cache/includes/elements/modplugin/7.include.cache.php, not from the original static element file. See Bug 11129


Such a plugin will replace the words on pages:

switch($eventName) {
    case 'OnWebPagePrerender': 
        // words to be replaced
        $words = array("Product", "Price");
        // get access to the page content
        $output = &$modx->resource->_output;
        // we replace words
        $output = str_replace($words,"changed",$output); 

See Also

Support the team building MODX with a monthly donation.

The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.



$0 per month—let's make that $500!

Learn more