Jump to main content Jump to doc navigation

OnLoadWebDocument

Other versions: 2.x (current) — Other languages: EN RU — Found a problem? Please edit this page or report an issue.

Event: OnLoadWebDocument

Fires directly before the Response is sent and after a Resource is loaded.

Service: 5 - Template Service Events Group: None

Event Parameters

None. The resource can be referenced via $modx->resource.

Return Values

Any values returned from this event will be written as errors to the logs.

Usage

* Some of this may not be accurate because I'm testing this via trial and error.

You can use this event to set resource parameters at runtime or perform logging. E.g.

// Set all pages to be uncached (for debugging)
$modx->resource->set('cacheable', 0);
// Or switch the template
$modx->resource->set('template', 6);
// Alternate syntax
$modx->resource->template = 6;

Note that modifying resource parameters during the first page load (before the resource is cached) will cause those parameters to be written to the cache file. E.g. changing the template at this point will cause the resource _content to store the contents of the newly referenced template.

After a page has been cached (i.e. not the first page load), you can append or prepend content (or overwrite it entirely) by modifying the _content property.

$modx->resource->_content = 'Content override';

See Also