public function prepareEngine(Engine $engine) { // set file extension // $engine->setFileExtension('php'); // Add folders $engine->addFolder('templates', APPPATH . 'templates'); $engine->addFolder('partials', APPPATH . 'templates/partials'); $engine->addFolder('staticpages', APPPATH . 'templates/staticpages'); }
/** * Create view template * * @return Engine */ public static function create(ServiceContainer $app) { $view = new Engine($app->config['path']['view'], null); // Add folder shortcut (assets::file.js) $view->addFolder('assets', $app->config['path']['assets']); $view->addFolder('view', $app->config['path']['view']); static::initViewCache($view, $app); return $view; }
public function __invoke(array $config) { $theme = $config['theme']; $templateEngine = new Engine(); $templateEngine->addFolder('app', 'templates'); $templateEngine->addFolder('theme', 'public/themes/' . $theme . '/templates'); $templateEngine->setFileExtension('phtml'); $templateEngine->loadExtensions([new AssetExt('public', true), new ThemeAssetExt('themes/' . $theme . '/assets')]); return new Application($config, new PlatesTemplateRenderer($templateEngine)); }
/** * Add a path for template * * Multiple calls to this method without a namespace will trigger an * E_USER_WARNING and act as a no-op. Plates does not handle non-namespaced * folders, only the default directory; overwriting the default directory * is likely unintended. * * @param string $path * @param string $namespace */ public function addPath($path, $namespace = null) { if (!$namespace && !$this->template->getDirectory()) { $this->template->setDirectory($path); return; } if (!$namespace) { trigger_error('Cannot add duplicate un-namespaced path in Plates template adapter', E_USER_WARNING); return; } $this->template->addFolder($namespace, $path, true); }
/** * Create instance * * @return Engine */ public function create(Request $request) { $engine = new Engine($this->options['view_path'], null); // Add folder shortcut (assets::file.js) $engine->addFolder('assets', $this->options['assets_path']); $engine->addFolder('view', $this->options['view_path']); $session = $request->getAttribute(SessionMiddleware::ATTRIBUTE); $baseUrl = $request->getAttribute('base_url'); // Register Asset extension $cacheOptions = array('cachepath' => $this->options['cache_path'], 'cachekey' => $session->get('user.locale'), 'baseurl' => $baseUrl, 'minify' => $this->options['minify']); $engine->loadExtension(new \Odan\Plates\Extension\AssetCache($cacheOptions)); return $engine; }
public function register() { $this->container->add('service.http.request', function () { return Request::createFromGlobals(); }); $this->container->add('service.http.route', function () { $route = new Route($this->container); foreach ($this->container->get('config')['http']['routes'] as $item) { $route->addRoute(strtoupper($item['method']), $item['path'], $item['target']); } return $route; }); $this->container->add('Symfony\\Component\\HttpFoundation\\Request', function () { return $this->container->get('service.http.request'); }); $this->container->add('service.view.view', function () { $view = new View(); foreach ($this->container->get('config')['http']['views_path'] as $name => $path) { $view->addFolder($name, $path); } $request = $this->container->get('service.http.request'); $view->loadExtension(new RequestExtension($request)); $view->loadExtension(new FlashBagExtension($request->getSession()->getFlashBag())); $view->loadExtension(new BaseUrlExtension($request->getBasePath())); $assetBaseUrl = $this->container->get('config')['asset_base_url']; $view->loadExtension(new AssetUrlExtension($assetBaseUrl)); if ($this->container->get('service.account.auth')->hasAuthenticatedUser()) { $authenticatedUser = $this->container->get('service.account.auth')->getAuthenticatedUser(); $view->loadExtension(new AuthenticatedUserExtension($authenticatedUser)); } $view->addData(['applicationName' => $this->container->get('config')['application_name']]); return $view; }); }
/** * Get a Plates engine * * @return \League\Plates\Engine */ public function getInstance() { if (!$this->engineInstance) { // Create new Plates engine $this->engineInstance = new \League\Plates\Engine($this->templatesPath ?: $this->getTemplatesDirectory()); if ($this->fileExtension) { $this->engineInstance->setFileExtension($this->fileExtension); } if (count($this->templatesFolders)) { foreach ($this->templatesFolders as $name => $path) { $this->engineInstance->addFolder($name, $path); } } } return $this->engineInstance; }
/** * PlatesProvider constructor. * @param Engine $plates * @param string $root_path * @param string $namespace */ public function __construct(Engine $plates, $root_path, $namespace) { $this->plates = $plates; $this->namespace = $namespace; if (!$plates->getFolders()->exists($namespace)) { $plates->addFolder($namespace, $root_path); } }
/** * Render a string * * @param string $template The template content to render * @param array $locals The variable to use in template * @return null|string */ public function render($template, array $locals = array()) { $tmpName = uniqid('plates_tmp_', false); $tmpPath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $tmpName; if (!is_null($this->plates->getFileExtension())) { $tmpPath .= '.' . $this->plates->getFileExtension(); } $isTmpRegister = $this->plates->getFolders()->exists(sys_get_temp_dir()); if (!$isTmpRegister) { $this->plates->addFolder(sys_get_temp_dir(), sys_get_temp_dir()); } file_put_contents($tmpPath, $template); $data = $this->plates->render(sys_get_temp_dir() . '::' . $tmpName, $locals); unlink($tmpPath); if (!$isTmpRegister) { $this->plates->getFolders()->remove(sys_get_temp_dir()); } return $data; }
public function __invoke(array $input) { $name = 'world'; if (!empty($input['name'])) { $name = $input['name']; } //////////////////// $application = new Application(); $application_data = $application->is_pjax(); //print_r( '<pre>' ); // print_r( $application_data ); //print_r( '</pre>'); //////////////////// // simple // Create new Plates instance // $plates = new Engine(APPPATH.'templates'); // Render a template // $template = $plates->render('partials/profile', ['name' => $name . ' | ' . $data_from_an_other_class]); // $template = $plates->render('partials/profile', ['name' => $name . ' | ' . $application_data]); $data = ['friends' => ['mikka', 'makka', 'zorro']]; // $friends = [ // ['name', 'zorro'], // ]; //////////////////// // using folders // Create new Plates instance $plates = new Engine(APPPATH . 'templates'); // Register a Plates extension $plates->loadExtension(new Utils()); // Add folders $plates->addFolder('layout', APPPATH . 'templates'); $plates->addFolder('partials', APPPATH . 'templates/partials'); $plates->addFolder('static', APPPATH . 'templates/static'); // assign data to plates $plates->addData($data, 'layout'); // Render $template = $plates->render('partials::profile', ['name' => $name]); //////////////////// $invitation = 'I invite you'; // return return (new Payload())->withStatus(Payload::OK)->withOutput(['hello' => $template, 'invitation' => $invitation]); }
/** * Get an instance of the Plates Engine * * @return \League\Plates\Engine */ public function getInstance() { if (!$this->engineInstance) { $this->engineInstance = new Engine($this->templatesPath ?: $this->getTemplatesDirectory()); if ($this->fileExtension) { $this->engineInstance->setFileExtension($this->fileExtension); } if (count($this->templatesFolders) > 0) { foreach ($this->templatesFolders as $name => $path) { $this->engineInstance->addFolder($name, $path); } } if (count($this->parserExtensions) > 0) { foreach ($this->parserExtensions as $extension) { $this->engineInstance->loadExtension($extension); } } } return $this->engineInstance; }
/** * Plates paths loader. */ protected function getLoader() : LeagueEngine { if (!$this->engine) { $config = $this->config; $this->engine = new LeagueEngine($config['template']['default'] ?? null, $config['engine']['plates']['file_extension'] ?? null); if (($paths = $config['template']['paths'] ?? null) !== null) { foreach ($paths as $name => $addPaths) { $this->engine->addFolder($name, $addPaths); } } } return $this->engine; }
/** * Add a new template folder for grouping templates under different namespaces. * * @param string $name Folder name * @param string $directory Folder path * @param bool $fallback Folder falback */ public function addFolder($name, $directory, $fallback = false) { $this->engine->addFolder($name, $directory, $fallback); return $this->engine; }
/** * Register template engine * * @return $this */ protected function registerTemplateEngine() { $container = $this->getContainer(); $this->getContainer()->add(Engine::class, function () use($container) { /** @var \Pagewire\Core\Application $app */ $app = $container->get(ApplicationInterface::class); $templates = $app->getConfig('templates', []); if (isset($templates['default'])) { $default = $templates['default']; unset($templates['default']); } else { $default = reset($templates); $defaultKey = key($default); unset($templates[$defaultKey]); } $engine = new Engine($default); foreach ($templates as $name => $template) { $engine->addFolder($name, $template, false); } return $engine; }); return $this; }
public function prepareEngine(Engine $engine) { $engine->addFolder('my', __DIR__ . '/../templates'); }
public function addTheme($themeName, $path) { $this->template->addFolder($themeName, $path); }
protected function addTemplateDir($name, $dir) { $this->templater->addFolder($name, $dir); }
* This line uses the Request class from the symfony/http-foundation package to * create a request object from the global variables ($_GET, $_POST, ...). * * Check out more information here: * http://symfony.com/doc/current/components/http_foundation/introduction.html */ $request = Request::createFromGlobals(); /* * Here we set up the templating engine that we're going to use to render our * templates. * * Check out more information here: * http://platesphp.com/engine/ */ $templatingEngine = new Engine(); $templatingEngine->addFolder('site', 'templates/site'); /* * Here we instantiate our controller using the class at src\SiteController.php. * * If you're going to add any more, make sure you 'use' them at the top of this * file. */ $siteController = new SiteController($templatingEngine); /* * Here we set up our router. This is the package that will match a request to * a method in our controller (sometimes called an action). This might seem * unnecessary, but routers can be really helpful as your site grows. * * Check out more information here: * * http://symfony.com/doc/current/components/routing/introduction.html
/** * setup the template engine and sends the parsed content to the engine * * @uses \League\Plates\Extension\Asset * @uses \League\Plates\Engine * @uses url * @since 1.0 */ public function setup() { $engine = new Engine($this->relativePath . "include" . DS . "styles" . DS . config::init()->style); $engine->loadExtension(new Asset($this->relativePath . "include" . DS . "styles" . DS . config::init()->style . DS . "assets", true)); // add infos for theme $this->setStyleParameter("isZipEnabled", false); $this->setStyleParameter("showWarnings", false); $breadcrumbs = $this->generateBreadcrumbs(url::GET("dir")); $this->setStyleParameter("breadcrumbs", $breadcrumbs); $this->setStyleParameter("assetspath", common::getRelativePath(getcwd(), dirname(__FILE__)) . DS . "styles" . DS . config::init()->style . DS . "assets"); $this->setStyleParameter("title", "SimpleDirLister | " . common::fixPaths(implode(DS, array_keys($breadcrumbs)))); $this->setStyleParameter("path", common::fixPaths(implode(DS, array_keys($breadcrumbs)))); $this->setStyleParameter("header", config::init()->header ? file::init(config::init()->header)->getFilename() : false); $this->setStyleParameter("footer", config::init()->footer ? file::init(config::init()->footer)->getFilename() : false); $engine->addFolder('static', $this->getBasePath() . DS . config::init()->headerFooterDir); try { $files = $this->getRawPaths(); $files = $this->cleanArray($files); if (config::init()->showReadme) { $readmeContent = []; foreach (config::init()->readme as $readme) { if (isset($files[$readme])) { $c = file_get_contents($files[$readme]["path"]); $ext = pathinfo($files[$readme]["path"], PATHINFO_EXTENSION); if ($ext == "md") { $md = new Parsedown(); $readmeContent[] = '<div class="md">' . $md->text($c) . '</div>'; } elseif ($ext == "php") { $readmeContent[] = (require $files[$readme]["path"]); } else { $readmeContent[] = $c; } if (config::init()->removeReadme) { unset($files[$readme]); } } } $this->setStyleParameter("readme", $readmeContent); } } catch (\Exception $e) { $this->setStyleParameter("showWarnings", true); $this->setStyleParameter("warnings", [["message" => "dir not found", "type" => "danger"]]); $files = []; } finally { $this->setStyleParameter("files", $files); } $engine->registerFunction('fileicon', [&$this, "getIconFromSet"]); $this->setStyleParameter("search", url::GET("s")); $engine->addData($this->styleParameter); if (!empty(url::GET("s"))) { echo $engine->render("search", $this->styleParameter); } else { echo $engine->render("index", $this->styleParameter); } }
/** * Add a new template folder for grouping templates under different namespaces. * * @param string $name Folder name * @param string $directory Folder path * @param bool $fallback Folder falback */ public function add_folder($name, $directory, $fallback = false) { $this->paths[$name] = $directory; $this->engine->addFolder($name, $directory, $fallback); return $this; }
/** * Add a new template folder for grouping templates under different namespaces. * * @param string $name * @param string $directory * @param boolean $fallback * @return \League\Plates\Engine */ public function addFolder($name, $directory, $fallback = false) { return $this->plates->addFolder($name, $directory, $fallback); }