I’m writing a simple plugin that checks for the existence of a cookie named ’flashme’ and creates a placeholder with that cookie’s contents, if it exists. Basically, I’m wanting to make those flash/session messages we’ve all seen (success/failure messages that fade away shortly after page load), and I’m trying to automate things a little bit. It seems to be working except that it never replaces the placeholder with the cookie. At least, it never shows up on the screen. I’ve verified it’s getting the document data and the flash message. When I view page source, the placeholder no longer exists in the source. Am I doing this at the proper event? Is there a built-in way that I’ve missed?
Here’s the plugin source:
// Check the event type
$e = &$modx->Event;
switch ($e->name) {
case "OnWebPagePrerender":
// Has a cookie been set?
if (isset($_COOKIE['flashme'])) {
// A cookie exists, so replace the [+flashme+] placeholder
// Get a reference to the document object.
$o = &$modx->documentOutput;
$msg = $_COOKIE["flashme"];
$o = str_replace("[+flashme+]", $msg, $o);
// Erase the cookie
setcookie("flashme", "", time()-3600);
}
break;
default:
return;
break;
}
Any help or ideas would be greatly appreciated!
Thanks!