octobercms/october — pull request #58 by Flynsarmy (2014-05-15 05:48:20+00:00)
Title: Only output result of a cms.beforeDsiplay if it has a output to return

cms.beforeDsiplay is currently used to output the results of the latest binding to the screen. This patch will only return the output to the screen if the event hook returned output to display.

Example use case

I have a plugin that uses cms.beforeDisplay to potentially trigger a redirect, however if I don't trigger a redirect, I want the page to continue loading as normal. Here is the basic pseudocode:
```php
Event::listen('cms.beforeDisplay', function($controller, $url, $page) {
if ( $url == $a_given_url )
{
header("Location: ".$match->to_url, true, $match->redirect_code);
exit;
}
});
```
The provided patch will allow this sort of thing to work. If a match isn't found, my event hook returns no output so the listener will continue the page load as normal.