/** * Get template filename * * @param string $template * @param [] $params * @return string|bool */ public function getTemplateFileName($template, $params = []) { $key = $template . '_' . serialize($params); if (!isset($this->_templateFilesMap[$key])) { $this->_templateFilesMap[$key] = $this->_viewFileSystem->getTemplateFileName($template, $params); } return $this->_templateFilesMap[$key]; }
public function testGetTemplateFileName() { $params = array('area' => 'some_area', 'themeModel' => $this->getMock('Magento\\Framework\\View\\Design\\ThemeInterface', array(), array(), '', false, false), 'module' => 'Some_Module'); $file = 'Some_Module::some_file.ext'; $expected = 'path/to/some_file.ext'; $this->_templateFileResolution->expects($this->once())->method('getFile')->with($params['area'], $params['themeModel'], 'some_file.ext', 'Some_Module')->will($this->returnValue($expected)); $this->_assetRepo->expects($this->any())->method('extractScope')->with($file, $params)->will($this->returnValue('some_file.ext')); $actual = $this->_model->getTemplateFileName($file, $params); $this->assertEquals($expected, $actual); }
/** * Render data * * @param UiComponentInterface $view * @param string $template * @return string */ public function render(UiComponentInterface $view, $template = '') { $templateEngine = false; if ($template) { $extension = pathinfo($template, PATHINFO_EXTENSION); $templateEngine = $this->templateEnginePool->get($extension); } if ($templateEngine) { $path = $this->filesystem->getTemplateFileName($template); $result = $templateEngine->render($view, $path); } else { $result = ''; } return $result; }
/** * Render data * * @param UiComponentInterface $view * @param string $template * @return string * @throws \Exception */ public function render(UiComponentInterface $view, $template = '') { $templateEngine = false; if ($template) { $extension = pathinfo($template, PATHINFO_EXTENSION); $templateEngine = $this->templateEnginePool->get($extension); } if ($templateEngine) { $path = $this->filesystem->getTemplateFileName($template); $result = $templateEngine->render($view, $path); } else { $result = $this->getDataXml($view); } throw new \Exception('Please implement XML renderer'); }
/** * Generate layout update xml * * @param string $container * @param string $templatePath * @return string * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function generateLayoutUpdateXml($container, $templatePath = '') { $templateFilename = $this->_viewFileSystem->getTemplateFileName($templatePath, ['area' => $this->getArea(), 'themeId' => $this->getThemeId(), 'module' => \Magento\Framework\View\Element\AbstractBlock::extractModuleName($this->getType())]); if (!$this->getId() && !$this->isCompleteToCreate() || $templatePath && !is_readable($templateFilename)) { return ''; } $parameters = $this->getWidgetParameters(); $xml = '<body><referenceContainer name="' . $container . '">'; $template = ''; if (isset($parameters['template'])) { unset($parameters['template']); } if ($templatePath) { $template = ' template="' . $templatePath . '"'; } $hash = $this->mathRandom->getUniqueHash(); $xml .= '<block class="' . $this->getType() . '" name="' . $hash . '"' . $template . '>'; foreach ($parameters as $name => $value) { if ($name == 'conditions') { $name = 'conditions_encoded'; $value = $this->conditionsHelper->encode($value); } elseif (is_array($value)) { $value = implode(',', $value); } if ($name && strlen((string) $value)) { $xml .= '<action method="setData">' . '<argument name="name" xsi:type="string">' . $name . '</argument>' . '<argument name="value" xsi:type="string">' . $this->_escaper->escapeHtml($value) . '</argument>' . '</action>'; } } $xml .= '</block></referenceContainer></body>'; return $xml; }
/** * Get absolute path to template * * @param string|null $template * @return string */ public function getTemplateFile($template = null) { $params = ['module' => $this->getModuleName()]; $area = $this->getArea(); if ($area) { $params['area'] = $area; } $templateName = $this->_viewFileSystem->getTemplateFileName($template ?: $this->getTemplate(), $params); return $templateName; }
/** * Render page template * * @return string * @throws \Exception */ protected function renderPage() { $fileName = $this->viewFileSystem->getTemplateFileName($this->template); if (!$fileName) { throw new \InvalidArgumentException('Template "' . $this->template . '" is not found'); } ob_start(); try { extract($this->viewVars, EXTR_SKIP); include $fileName; } catch (\Exception $exception) { ob_end_clean(); throw $exception; } $output = ob_get_clean(); return $output; }
public function testGetTemplateFileName() { $expected = '%s/frontend/Test/default/Magento_Catalog/templates/theme_template.phtml'; $actual = $this->_model->getTemplateFileName('Magento_Catalog::theme_template.phtml', []); $this->_testExpectedVersusActualFilename($expected, $actual); }