/** * @param string $viewHelperTemplate * @param string $expectedOutput * * @test * @dataProvider viewHelperTemplateSourcesDataProvider */ public function renderingTest($viewHelperTemplate, $expectedOutput) { $view = new TemplateView(); $view->assign('settings', ['test' => '<strong>Bla</strong>']); $templateString = '{namespace ft=TYPO3Fluid\\FluidTest\\ViewHelpers}'; $templateString .= $viewHelperTemplate; $view->getRenderingContext()->getViewHelperResolver()->addNamespace('ft', 'TYPO3Fluid\\FluidTest\\ViewHelpers'); $view->getRenderingContext()->getTemplatePaths()->setTemplateSource($viewHelperTemplate); $this->assertSame($expectedOutput, $view->render()); }
/** * Render the given template as ICS file * * @param string $actionName * * @return void */ public function render($actionName = NULL) { $content = parent::render($actionName); header('Content-type: text/calendar; charset=utf-8'); header('Content-Disposition: inline; filename=event.ics'); echo $content; die; }
/** * Inject an view object to be able to set templateRootPath from flexform * * @param \TYPO3\CMS\Extbase\Mvc\View\ViewInterface $view * @return void */ protected function initializeView(\TYPO3\CMS\Extbase\Mvc\View\ViewInterface $view) { if (isset($this->settings['templateRootPath']) && !empty($this->settings['templateRootPath'])) { $templateRootPath = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($this->settings['templateRootPath'], true); if (\TYPO3\CMS\Core\Utility\GeneralUtility::isAllowedAbsPath($templateRootPath)) { $this->view->setTemplateRootPaths(array($templateRootPath)); } } }
/** * Build a fluid renderer object * * @return TYPO3\CMS\Fluid\View\TemplateView */ protected static function getFluidRenderer() { if (!self::$fluidRenderer) { $objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager'); self::$fluidRenderer = $objectManager->get('TYPO3\\CMS\\Fluid\\View\\TemplateView'); $controllerContext = $objectManager->get('Tx_PtExtlist_Extbase_ExtbaseContext')->getControllerContext(); self::$fluidRenderer->setControllerContext($controllerContext); } return self::$fluidRenderer; }
/** * Gets the message for a notification mail as fluid template * * @param Comment $comment comment which triggers the mail send method * @return string The rendered fluid template (HTML or plain text) * * @throws \Exception */ protected function getMailMessage(Comment $comment) { $mailTemplate = GeneralUtility::getFileAbsFileName($this->getTemplatePath()); if (!file_exists($mailTemplate)) { throw new \Exception('Mail template (' . $mailTemplate . ') not found. '); } $this->fluidTemplate->setTemplatePathAndFilename($mailTemplate); // Assign variables $this->fluidTemplate->assign('comment', $comment); $this->fluidTemplate->assign('settings', $this->settings); $uriBuilder = $this->controllerContext->getUriBuilder(); $subFolder = $this->settings['subFolder'] ? $this->settings['subFolder'] : ''; $articleLink = 'http://' . GeneralUtility::getHostname() . $subFolder . '/' . $uriBuilder->setTargetPageUid($comment->getPid())->setAddQueryString($this->getAddQueryStringToLinks())->setArgumentsToBeExcludedFromQueryString(array('id', 'cHash', 'tx_pwcomments_pi1[action]', 'tx_pwcomments_pi1[controller]'))->setUseCacheHash(FALSE)->buildFrontendUri(); $this->fluidTemplate->assign('articleLink', $articleLink); $backendDomain = $this->settings['overwriteBackendDomain'] ? $this->settings['overwriteBackendDomain'] : GeneralUtility::getHostname(); $backendLink = 'http://' . $backendDomain . $subFolder . '/typo3/alt_doc.php?M=web_list&id=' . $comment->getPid() . '&edit[tx_pwcomments_domain_model_comment][' . $comment->getUid() . ']=edit'; $this->fluidTemplate->assign('backendLink', $backendLink); return $this->fluidTemplate->render(); }
/** * Renders a section from the specified template w/o requring a call to the * main render() method - allows for cherry-picking sections to render. * * @param string $sectionName * @param array $variables * @param boolean $optional * @return string */ public function renderStandaloneSection($sectionName, $variables, $optional = TRUE) { $content = NULL; $this->baseRenderingContext->setControllerContext($this->controllerContext); $this->startRendering(AbstractTemplateView::RENDERING_TEMPLATE, $this->getParsedTemplate(), $this->baseRenderingContext); $content = parent::renderSection($sectionName, $variables, $optional); $this->stopRendering(); return $content; }
/** * Init view */ public function initializeView() { $this->templateView->initializeView(); }
/** * assign content * * @return MailView */ protected function assignContent() { $html = parent::render(); $request = $this->controllerContext->getRequest(); $resetFormat = $request->getFormat(); $request->setFormat('txt'); if ($this->canRender($this->controllerContext)) { $txt = parent::render(); } $request->setFormat($resetFormat); $this->mail->setBody($html, 'text/html'); if (isset($txt) && strlen($txt)) { $this->mail->addPart($txt, 'text/plain'); } return $this; }
/** * Render XML Content as single Output */ public function render() { $c = parent::render(); header("Content-Type:text/xml"); die($c); }
/** * We use a checksum of the template source as the template identifier * * @param string $actionName * @return string */ protected function getTemplateIdentifier($actionName = NULL) { $hasMethodOnParent = TRUE === method_exists(get_parent_class($this), __FUNCTION__); $templateFileExists = TRUE === file_exists($this->templatePathAndFilename); return TRUE === $hasMethodOnParent && TRUE === $templateFileExists ? parent::getTemplateIdentifier($actionName) : 'viewhelpertest_' . sha1($this->templateSource); }
/** * Resolve the template path and filename for the given action. If $actionName * is NULL, looks into the current request. * * Tries to read template path and filename from current settings. * Path can be set there by $controller->setTemplatePathAndFilename(Path to template) * * @param string $actionName Name of the action. If NULL, will be taken from request. * @return string Full path to template * @throws TYPO3\CMS\Fluid\View\Exception\InvalidTemplateResourceException */ protected function getTemplatePathAndFilename($actionName = null) { if ($this->templatePathAndFilename != '') { if (file_exists($this->templatePathAndFilename)) { return $this->templatePathAndFilename; } if (file_exists(GeneralUtility::getFileAbsFileName($this->templatePathAndFilename))) { return GeneralUtility::getFileAbsFileName($this->templatePathAndFilename); } } else { if (method_exists('\\TYPO3\\CMS\\Fluid\\View\\TemplateView', 'getTemplatePathAndFilename')) { return parent::getTemplatePathAndFilename($actionName); // this method only exists in 1.4.0 } else { return $actionName; } } }
/** * * @param \TYPO3\Sessions\Domain\Model\AnySession $session * @return string */ public function infoAction($session) { $this->view->assign('session', $session); }
/** * Initializes Template in Fluid renderer */ protected function initTemplate() { $fullQualifiedTemplatePath = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($this->templatePath); $this->fluidRenderer->setTemplatePathAndFilename($fullQualifiedTemplatePath); }