public function __construct() { $paths = new \TYPO3Fluid\Fluid\View\TemplatePaths(); $paths->setTemplateRootPaths(array(ROOT_PATH . '/Templates/')); $paths->setLayoutRootPaths(array(ROOT_PATH . '/Layouts/')); $paths->setPartialRootPaths(array(ROOT_PATH . '/Partials/')); $this->view = new \TYPO3Fluid\Fluid\View\TemplateView(); }
public function render($template, $variables = array()) { $paths = new \TYPO3Fluid\Fluid\View\TemplatePaths(); // $paths->setTemplateRootPaths(array(__DIR__ . '/../Templates/')); $paths->setLayoutRootPaths(array(BASE_DIRECTORY . '/../Resources/Layouts/')); $paths->setPartialRootPaths(array(BASE_DIRECTORY . '/../Resources/Partials/')); $parts = explode('/', $template); array_walk($parts, function (&$value, $key) { $value = ucfirst($value); }); $path = implode('/', $parts); $templateFile = BASE_DIRECTORY . '/../Resources/Templates/' . $path . '.html'; $paths->setTemplatePathAndFilename($templateFile); $view = new TemplateView($paths); $view->assignMultiple($variables); $view->getViewHelperResolver()->registerNamespace('s', 'Famelo\\Soup\\ViewHelpers'); echo $view->render(); }
<?php $FLUID_CACHE_DIRECTORY = !isset($FLUID_CACHE_DIRECTORY) ? __DIR__ . '/../cache/' : $FLUID_CACHE_DIRECTORY; // Use Composer's autoloader to handle our class loading. require_once __DIR__ . '/../vendor/autoload.php'; $templatePaths = new \TYPO3Fluid\Fluid\View\TemplatePaths(); $templatePaths->setTemplateRootPaths(array(__DIR__ . '/../Resources/Private/Templates/')); $templatePaths->setLayoutRootPaths(array(__DIR__ . '/../Resources/Private/Layouts/')); $templatePaths->setPartialRootPaths(array(__DIR__ . '/../Resources/Private/Partials/')); $view = new \TYPO3Fluid\Fluid\View\TemplateView($templatePaths); if ($FLUID_CACHE_DIRECTORY) { $view->setCache(new \TYPO3Fluid\Fluid\Core\Cache\SimpleFileCache($FLUID_CACHE_DIRECTORY)); } $view->getRenderingContext()->setControllerName('Page'); try { if (array_key_exists('PATH_INFO', $_SERVER)) { $path = substr($_SERVER['PATH_INFO'], 1); if ($path === FALSE) { $path = 'index'; } } else { $path = 'index'; } $output = $view->render($path); } catch (\Exception $exception) { $output = $view->render('error'); } echo $output;