View • Attachments (0) • Info
Plugins are similar to snippets in that they are snippets of code that have access to the MODx API - however the big difference is that plugins are associated to specific system events. For example, in an average MODx page request, several events happen at certain points within the page parsing process and plugins can be attached to any of these events to fulfill a desired function. Plugins aren't just limited to front-end processing though, there are many events that are available in the MODx Manager.
Plugins can be used for a variety of different applications, below are a couple of examples:
Description: Filter words from a document before it's displayed on the web
System Events: OnWebPagePrerender
$words = array("snippet", "template"); // words to filter $e = &$modx->Event; switch ($e->name) { case "OnWebPagePrerender": $o = &$modx->documentOutput; // get a reference of the output $o = str_replace($words,"<b>[filtered]</b>",$o); break; default : return; // stop here - this is very important. break; }
Description: Redirects a user to selected document and sends a message
System Events: OnPageNotFound
Config: String:
&pg=Error Page;int; &rep=Mail To;string;
$e = &$modx->Event; switch ($e->name) { case "OnPageNotFound": if(!$pg) $modx->sendErrorPage(); else { if ($mid) { // send a message to a local account $docid = $modx->documentIdentifier; $subject = "Page not found"; $msg = "Someone tried to access document id $docid"; $modx->sendAlert("Error",$mid,0,$subject,$msg,0); } $url=$this->makeUrl($pg); $this->sendRedirect($url, 1); exit; } break; default : return; // stop here break; }
|
Browse Space |
Explore Confluence |
Your Account |
Add Content |
|
Powered by Atlassian Confluence 2.7.1, the Enterprise Wiki. |