The onBeforeOutput handler works very similarly to the onOutput handler, except that it is run before widgets have been processed (i.e., they still appears as <widget id="... in the $buffer).

Furthermore, as the below example indicates, REGISTERED_BODY_CLASSES haven’t yet been added to the page HTML, so you can still edit that array.

       'title'=>'My App',

    class LiveWhaleApplicationMyApp {

      public function onBeforeOutput($buffer) {
      global $_LW;

        // add page_id_123 to the body class
        $_LW->applyPageAndGroupVars('<xphp var="page_id"/>');
        if (!empty($GLOBALS['page_id'])) {
        return $buffer;