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

None.

Example

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

Example

Such a plugin will replace the words on pages:

<?php
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); 
        break;
}

See Also