Exemplo n.º 1
0
 /**
  * static function to render a document outside of a view
  *
  * @static
  * @param Document $document
  * @param array $params
  * @return
  */
 public static function render(Document $document, $params = array())
 {
     $view = new Pimcore_View();
     $params["document"] = $document;
     $content = $view->action($document->getAction(), $document->getController(), null, $params);
     return $content;
 }
Exemplo n.º 2
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;
 }