OnWebPagePrerender
Last updated Nov 27th, 2019 | Page history | Improve this page | Report an issue
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.
Backers
Budget
$311 per month—let's make that $500!
Learn moreEvent: 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¶
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.
Backers
Budget
$311 per month—let's make that $500!
Learn more