getViewScriptSuffix() public static method

public static getViewScriptSuffix ( ) : string
return string
Example #1
0
 /**
  * @param null $path
  * @param null $prefix
  * @param array $options
  */
 public function initView($path = null, $prefix = null, array $options = array())
 {
     if (null === $this->view) {
         $view = new View();
         $view->setRequest($this->getRequest());
         $view->addHelperPath(PIMCORE_PATH . "/lib/Pimcore/View/Helper", "\\Pimcore\\View\\Helper\\");
         $this->setView($view);
     }
     parent::initView($path, $prefix, $options);
     $this->setViewSuffix(View::getViewScriptSuffix());
     // this is very important, the initView could be called multiple times.
     // if we add the path on every call, we have big performance issues.
     if ($this->isInitialized) {
         return;
     }
     $this->isInitialized = true;
     $paths = $this->view->getScriptPaths();
     // script pathes for layout path
     foreach (array_reverse($paths) as $path) {
         $path = str_replace("\\", "/", $path);
         if (!in_array($path, $paths)) {
             $this->view->addScriptPath($path);
         }
         $path = str_replace("/scripts", "/layouts", $path);
         if (!in_array($path, $paths)) {
             $this->view->addScriptPath($path);
         }
     }
 }
Example #2
0
 /**
  * @return null|\Zend_Layout
  * @throws \Zend_Controller_Action_Exception
  */
 protected function enableLayout()
 {
     $viewRenderer = \Zend_Controller_Action_HelperBroker::getExistingHelper("viewRenderer");
     $viewRenderer->setIsInitialized(false);
     // reset so that the view get's initialized again, because of error page from other modules
     $viewRenderer->initView();
     \Zend_Layout::startMvc();
     $layout = \Zend_Layout::getMvcInstance();
     $layout->enableLayout();
     $layout->setViewSuffix(\Pimcore\View::getViewScriptSuffix());
     return $layout;
 }
Example #3
0
 public function getAvailableTemplatesAction()
 {
     $templates = [];
     $viewPath = PIMCORE_WEBSITE_PATH . DIRECTORY_SEPARATOR . "views" . DIRECTORY_SEPARATOR . "scripts";
     $files = rscandir($viewPath . DIRECTORY_SEPARATOR);
     foreach ($files as $file) {
         $dat = [];
         if (strpos($file, \Pimcore\View::getViewScriptSuffix()) !== false) {
             $dat["path"] = str_replace($viewPath, "", $file);
             $dat["path"] = str_replace("\\", "/", $dat["path"]);
             // unix directory separator are compatible with windows, not the reverse
             $templates[] = $dat;
         }
     }
     $this->_helper->json(["data" => $templates]);
 }
Example #4
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)
 {
     $layout = null;
     $existingActionHelper = null;
     if (\Zend_Controller_Action_HelperBroker::hasHelper("layout")) {
         $existingActionHelper = \Zend_Controller_Action_HelperBroker::getExistingHelper("layout");
     }
     $layoutInCurrentAction = \Zend_Layout::getMvcInstance() instanceof \Zend_Layout ? \Zend_Layout::getMvcInstance()->getLayout() : 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
     $moduleDirectory = \Zend_Controller_Front::getInstance()->getModuleDirectory($document->getModule());
     if (!empty($moduleDirectory)) {
         $view->addScriptPath($moduleDirectory . "/views/layouts");
         $view->addScriptPath($moduleDirectory . "/views/scripts");
     } else {
         $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;
     if ($useLayout) {
         if (!($layout = \Zend_Layout::getMvcInstance())) {
             $layout = \Zend_Layout::startMvc();
             $layout->setViewSuffix(View::getViewScriptSuffix());
             if ($layoutHelper = $view->getHelper("layout")) {
                 $layoutHelper->setLayout($layout);
             }
         }
         $layout->setLayout("--modification-indicator--");
     }
     $params["document"] = $document;
     foreach ($params as $key => $value) {
         if (!$view->{$key}) {
             $view->{$key} = $value;
         }
     }
     $content = $view->action($document->getAction(), $document->getController(), $document->getModule(), $params);
     //has to be called after $view->action so we can determine if a layout is enabled in $view->action()
     if ($useLayout) {
         if ($layout instanceof \Zend_Layout) {
             $layout->{$layout->getContentKey()} = $content;
             if (is_array($params)) {
                 foreach ($params as $key => $value) {
                     $layout->getView()->{$key} = $value;
                 }
             }
             // when using Document\Service::render() you have to set a layout in the view ($this->layout()->setLayout("mylayout"))
             if ($layout->getLayout() != "--modification-indicator--") {
                 $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
             \Zend_Layout::resetMvcInstance();
             if (!$layoutInCurrentAction) {
                 $layout->disableLayout();
             } else {
                 $layout = \Zend_Layout::startMvc();
                 $layout->setViewSuffix(View::getViewScriptSuffix());
                 // set pimcore specifiy view suffix
                 $layout->setLayout($layoutInCurrentAction);
                 $view->getHelper("Layout")->setLayout($layout);
                 if ($existingActionHelper) {
                     \Zend_Controller_Action_HelperBroker::removeHelper("layout");
                     \Zend_Controller_Action_HelperBroker::addHelper($existingActionHelper);
                     $pluginClass = $layout->getPluginClass();
                     $front = $existingActionHelper->getFrontController();
                     if ($front->hasPlugin($pluginClass)) {
                         $plugin = $front->getPlugin($pluginClass);
                         $plugin->setLayoutActionHelper($existingActionHelper);
                     }
                 }
             }
             $layout->{$layout->getContentKey()} = null;
             //reset content
         }
     }
     if ($documentBackup) {
         $view->document = $documentBackup;
     }
     if (\Pimcore\Config::getSystemConfig()->outputfilters->less) {
         $content = \Pimcore\Tool\Less::processHtml($content);
     }
     return $content;
 }