/** * Widgets get rendered in a variety of contexts (e.g. in layouts, views, * and via xhr/partial). Consequently, head resources (e.g. scripts, styles, * dojo, etc) may or may not have been emitted already. Therefore, we want * to ensure that only the resources needed by this widget are emitted at * this time. * * To accomplish this, we cache out and clear the original set of head * resources prior to invoking the widget. After running the widget, we * print newly accumulated head resources and restore the original set. */ $originalScripts = clone $this->getHelper('headScript')->getContainer(); $originalStyles = clone $this->getHelper('headStyle')->getContainer(); $originalDojo = clone $this->getHelper('dojo')->getContainer(); $this->headScript()->getContainer()->set(array()); $this->headStyle()->getContainer()->set(array()); $this->dojo()->clearModulePaths() ->clearModules() ->clearJavascript() ->clearOnLoad() ->clearZendLoad(); // execute widget and buffer output. $widgetOutput = $this->widget->run(); // include widget requirements. echo $this->dojo('extras'), $this->headScript(), $this->headStyle(); // restore original head resources. $this->getHelper('headScript')->setContainer($originalScripts); $this->getHelper('headStyle')->setContainer($originalStyles); $this->getHelper('dojo')->setContainer($originalDojo); ?>