Exemple #1
0
 /**
  * static function to render a document outside of a view
  *
  * @static
  * @param Document $document
  * @param array $params
  * @param bool $useLayout
  * @return string
  */
 public static function render(Document $document, $params = array(), $useLayout = false)
 {
     $layoutEnabledInCurrentAction = Zend_Layout::getMvcInstance() instanceof Zend_Layout ? true : false;
     $viewHelper = Zend_Controller_Action_HelperBroker::getExistingHelper("ViewRenderer");
     if ($viewHelper) {
         if ($viewHelper->view === null) {
             $viewHelper->initView(PIMCORE_WEBSITE_PATH . "/views");
         }
         $view = $viewHelper->view;
     } else {
         $view = new Pimcore_View();
     }
     // add the view script path from the website module to the view, because otherwise it's not possible to call
     // this method out of other modules to render documents, eg. sending e-mails out of an plugin with Pimcore_Mail
     $view->addScriptPath(PIMCORE_FRONTEND_MODULE . "/views/layouts");
     $view->addScriptPath(PIMCORE_FRONTEND_MODULE . "/views/scripts");
     $documentBackup = null;
     if ($view->document) {
         $documentBackup = $view->document;
     }
     $view->document = $document;
     $params["document"] = $document;
     $content = $view->action($document->getAction(), $document->getController(), null, $params);
     //has to be called after $view->action so we can determine if a layout is enabled in $view->action()
     if ($useLayout) {
         $layout = Zend_Layout::getMvcInstance();
         if ($layout instanceof Zend_Layout) {
             $layout->{$layout->getContentKey()} = $content;
             if (is_array($params)) {
                 foreach ($params as $key => $value) {
                     if (!$layout->getView()->{$key}) {
                         //otherwise we could overwrite e.g. controller, content...
                         $layout->getView()->{$key} = $value;
                     }
                 }
             }
             $content = $layout->render();
             //deactivate the layout if it was not activated in the called action
             //otherwise we would activate the layout in the called action
             if (!$layoutEnabledInCurrentAction) {
                 $layout->disableLayout();
             }
             $layout->{$layout->getContentKey()} = null;
             //reset content
             $layout->resetMvcInstance();
         }
     }
     if ($documentBackup) {
         $view->document = $documentBackup;
     }
     return $content;
 }
Exemple #2
0
 protected function initCustomView()
 {
     $viewHelper = Zend_Controller_Action_HelperBroker::getExistingHelper("ViewRenderer");
     $view = new Pimcore_View();
     // script pathes
     foreach ($viewHelper->view->getScriptPaths() as $path) {
         $view->addScriptPath($path);
         $view->addScriptPath(str_replace(DIRECTORY_SEPARATOR . "scripts", DIRECTORY_SEPARATOR . "layouts", $path));
     }
     // view helper
     foreach ($viewHelper->view->getHelperPaths() as $prefix => $path) {
         $view->addHelperPath($path, $prefix);
     }
     $view->addHelperPath(PIMCORE_PATH . "/lib/Pimcore/View/Helper", "Pimcore_View_Helper_");
     // add helper to controller
     $viewHelper->setView($view);
     $viewHelper->setViewSuffix($this->getViewSuffix());
     Zend_Controller_Action_HelperBroker::addHelper($viewHelper);
     $this->view = $view;
     Zend_Registry::set("pimcore_custom_view", true);
 }