public function __construct($view, \Admin\Core\Helper $helper, \TYPO3\FLOW3\Object\ObjectManagerInterface $objectManager) { $this->helper = $helper; $this->view = $view; $this->objectManager = $objectManager; $partial = $this->getName(); $replacements = array("@partial" => $partial, "@package" => $this->helper->getPackageByClassName(get_class($this)), "@being" => \Admin\Core\Helper::getShortName(\Admin\Core\API::get("being")), "@action" => $partial); $template = $this->helper->getPathByPatternFallbacks("DashboardWidgets", $replacements); $this->view->setTemplatePathAndFilename($template); $this->initializeWidget(); }
public function renderPartial($variant = "Default") { $replacements = array("@partial" => "Field", "@package" => \Admin\Core\API::get("package"), "@being" => \Admin\Core\Helper::getShortName(\Admin\Core\API::get("being")), "@action" => "Field", "@variant" => $variant); $cache = $this->cacheManager->getCache('Admin_TemplateCache'); $identifier = str_replace("\\", "_", implode("-", $replacements)); $identifier = str_replace(".", "_", $identifier); if (!$cache->has($identifier)) { $template = $this->helper->getPathByPatternFallbacks("Partials", $replacements); $cache->set($identifier, $template); } else { $template = $cache->get($identifier); } $this->view = $this->viewHelperVariableContainer->getView(); $this->view->setTemplatePathAndFilename($template); return $this->view->render(); }
/** * * @param object $value * @param string $partial * @param string $fallbacks * @param array $vars * @param string $section * @param mixed $optional * @param string $variant * @return string Rendered string * @author Marc Neuhaus <*****@*****.**> * @api */ public function render($value = '', $partial = '', $fallbacks = '', $vars = array(), $section = null, $optional = false, $variant = "Default") { if ($value !== '') { return $value; } if ($partial !== '') { if ($fallbacks !== '') { $replacements = array("@partial" => $partial, "@package" => \Admin\Core\API::get("package"), "@being" => \Admin\Core\Helper::getShortName(\Admin\Core\API::get("being")), "@action" => $partial, "@variant" => $variant); $cache = $this->cacheManager->getCache('Admin_TemplateCache'); $identifier = str_replace("\\", "_", implode("-", $replacements)); $identifier = str_replace(".", "_", $identifier); $identifier = str_replace("/", "_", $identifier); if (!$cache->has($identifier)) { $template = $this->helper->getPathByPatternFallbacks($fallbacks, $replacements); $cache->set($identifier, $template); } else { $template = $cache->get($identifier); } if (empty($vars)) { $this->view = $this->viewHelperVariableContainer->getView(); $this->view->setTemplatePathAndFilename($template); if (!empty($template)) { return $this->view->render(); } } else { $partial = $this->parseTemplate($template); $variableContainer = $this->objectManager->create('TYPO3\\Fluid\\Core\\ViewHelper\\TemplateVariableContainer', $vars); $renderingContext = $this->buildRenderingContext($variableContainer); return $partial->render($renderingContext); } } } if ($section !== null) { $output = $this->viewHelperVariableContainer->getView()->renderSection($section, $vars, $optional); if (strlen($output) < 1) { $output = $this->renderChildren(); } return $output; } }
public function setTemplate($action) { $replacements = array("@action" => ucfirst($action), "@variant" => "Default", "@package" => "Admin"); if (!empty($this->being)) { if (class_exists($this->being, false)) { $replacements["@package"] = $this->helper->getPackageByClassName($this->being) ? $this->helper->getPackageByClassName($this->being) : "Admin"; $replacements["@being"] = \Admin\Core\Helper::getShortName($this->being); $being = $this->helper->getBeing($this->being); $replacements["@variant"] = $being->variant->getVariant($action); } } if ($this->request->hasArgument("variant")) { $replacements["@variant"] = $this->request->getArgument("variant"); } $cache = $this->cacheManager->getCache('Admin_TemplateCache'); $identifier = str_replace(".", "_", implode("-", $replacements)); $noTemplate = false; if (!$cache->has($identifier)) { try { $template = $this->helper->getPathByPatternFallbacks("Views", $replacements); } catch (\Exception $e) { $noTemplate = true; } if (!$noTemplate) { $cache->set($identifier, $template); } } else { $template = $cache->get($identifier); } if (!$noTemplate) { $this->view->setTemplatePathAndFilename($template); if ($this->request->hasArgument("being")) { $meta["being"]["identifier"] = $this->request->getArgument("being"); $meta["being"]["name"] = $this->request->getArgument("being"); \Admin\Core\API::set("package", $replacements["@package"]); } } }