public function testActionMethodExists() { $engine = new \League\Plates\Engine(); $ext = new \werx\Url\Extensions\Plates(); $engine->loadExtension($ext); $template = new \League\Plates\Template($engine); $this->assertTrue(method_exists($template->url(), 'action'), 'The action method from werx\\Url\\Builder should be available'); }
public function register(Application $app) { $app->set("View", function ($baseDir = null) use($app) { $baseDir = $baseDir ?: APP_PATH . 'views'; $plates = new \League\Plates\Engine(); $plates->loadExtension(new URI($app->Request->getPathInfo())); $plates->setDirectory($baseDir); return $plates; }); }
/** * Affiche un template * * @param string $file Chemin vers le template, relatif à app/templates/ * @param array $data Données à rendre disponibles à la vue */ public function show($file, array $data = array()) { //incluant le chemin vers nos templates $engine = new \League\Plates\Engine('../app/templates'); //charge nos extensions (nos fonctions personnalisées) $engine->loadExtension(new \W\View\Plates\PlatesExtensions()); //rend certaines données disponibles à tous les templates //accessible avec $w_user dans les fichiers de vue $engine->addData(array("w_user" => $this->getUser())); //retire l'éventuelle extension .php $file = str_replace(".php", "", $file); // Affiche le template echo $engine->render($file, $data); die; }
/** * Affiche un template * @param string $file Chemin vers le template, relatif à app/Views/ * @param array $data Données à rendre disponibles à la vue */ public function show($file, array $data = array()) { //incluant le chemin vers nos vues $engine = new \League\Plates\Engine(self::PATH_VIEWS); //charge nos extensions (nos fonctions personnalisées) $engine->loadExtension(new \W\View\Plates\PlatesExtensions()); $app = getApp(); // Rend certaines données disponibles à tous les vues // accessible avec $w_user & $w_current_route dans les fichiers de vue $engine->addData(['w_user' => $this->getUser(), 'w_current_route' => $app->getCurrentRoute()]); // Retire l'éventuelle extension .php $file = str_replace('.php', '', $file); // Affiche le template echo $engine->render($file, $data); die; }
/** * process the request so we can work out * what view we need to process and serve * * @access public * @return object DocMark\System\View Object */ public function process() { $query = $this->request->query->keys(); // setup the root for all the doc files $docRoot = ROOT . $this->config['docs']['root']; if (isset($query['0']) && !empty($query['0'])) { $this->url = $query['0'] = rtrim($query['0'], '/'); $query['0'] = ltrim($query['0'], '/'); $queryBits = explode('/', $query['0']); } else { // homepage $queryBits = array(); $isHome = true; } $path = $this->findFile($queryBits, $docRoot); // set the template engine and set fallback theme $templates = new \League\Plates\Engine(ROOT . 'themes' . DS . 'fallback'); // set the defined user theme if (file_exists(ROOT . 'themes' . DS . $this->config['themeName']) && is_dir(ROOT . 'themes' . DS . $this->config['themeName'])) { $templates->addFolder($this->config['themeName'], ROOT . 'themes' . DS . $this->config['themeName'], true); } // set the path to the assets to run through plates $templates->loadExtension(new \Snscripts\AdvancedAssets\Assets(ROOT, new \Symfony\Component\Filesystem\Filesystem())); // load the converter $converter = new \Michelf\MarkdownExtra(); if ($path !== false && isset($isHome) && $isHome) { return new \DocMark\System\View\Home($this, $converter, $templates, $path); } elseif ($path !== false && (!isset($isHome) || $isHome === false)) { return new \DocMark\System\View\Page($this, $converter, $templates, $path); } else { return new \DocMark\System\View\Error($this, $converter, $templates, $path); } }
* * file: index.php * version: 1.3 * coder: Simone De Gregori * */ // load configuration include $_SERVER['HOME'] . '/app/config/config.php'; // main include include $_SERVER['HOME'] . '/app/libs/vendor/autoload.php'; // open session session_start(); // plates: create new engine $engine = new \League\Plates\Engine('/srv/http/app/templates'); // plates: load asset extension $engine->loadExtension(new \League\Plates\Extension\Asset('/srv/http/assets', true)); // plates: load URI extension $engine->loadExtension(new \League\Plates\Extension\URI($_SERVER['REQUEST_URI'])); // plates: create a new template $template = new \League\Plates\Template($engine); // set devmode $template->dev = $devmode; // activePlayer $activePlayer = $redis->get('activePlayer'); // TODO: rework needed $template->activePlayer = $activePlayer; // allowed controllers $controllers = array('credits', 'coverart', 'dev', 'debug', 'help', 'index', 'login', 'mpd', 'network', 'playback', 'settings', 'sources', 'tun'); // check page if (in_array($template->uri(1), $controllers) or empty($template->uri(1))) { // decode REQUEST_URL and assing section
<?php use Zend\Stratigility\MiddlewarePipe; use Zend\Diactoros\Server; use League\Plates\Extension\URI as PlatesUri; chdir(dirname(__DIR__)); require 'vendor/autoload.php'; // Decline static file requests back to the PHP built-in webserver if (php_sapi_name() === 'cli-server') { $path = realpath(__DIR__ . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)); if (__FILE__ !== $path && is_file($path)) { return false; } unset($path); } $app = new MiddlewarePipe(); $server = Server::createServer($app, $_SERVER, $_GET, $_POST, $_COOKIE, $_FILES); $routes = (require 'config/routes.php'); // Routing system $app->pipe('/', function ($req, $res, $next) use($routes) { $path = $req->getUri()->getPath(); $template = new League\Plates\Engine(__DIR__ . '/../views'); $template->loadExtension(new PlatesUri($req->getUri()->getPath())); // 404 error if (!in_array($path, array_keys($routes))) { return $res->withStatus('404')->end($template->render('404')); } $route = new $routes[$path]($template); return $res->end($route($req, $res, $next)); }); $server->listen();
public function renderpage($po_page) { // Get view folder and file $ls_viewfolder = $this->getviewfolder($po_page); $ls_viewfile = $this->getviewfile($po_page); $ls_templatefolder = $this->gettemplatefolder($po_page); $ls_partialfolder = $this->getpartialfolder($po_page); $ls_assetsfolder = $this->getasstesfolder($po_page); // Get the data $la_viewdata = $this->getviewdata(); $la_templatedata = $this->gettemplatedata(); // Has view ? $lb_hasview = $this->hasview($po_page); // If no view is defined and view data is set throw error if (!$lb_hasview && !empty($la_viewdata)) { trigger_error('View not defined: ' . $ls_viewfolder . '/' . $ls_viewfile, E_USER_ERROR); } // Dont show anything if no view is defined if (!$lb_hasview) { return false; } // Create new Plates instance $lo_templates = new \League\Plates\Engine($ls_viewfolder); // Load URI extension $lo_templates->loadExtension(new \League\Plates\Extension\URI($this->getcurrenturl())); // Load asset extension $lo_templates->loadExtension(new AssetExtension($ls_assetsfolder, true)); // Prepate the HTML extension for the template engine $lo_htmlextension = new HtmlExtension(); // Inject any validation errors that we accumulated $lo_htmlextension->setformerrors($this->getformerrors()); // Load html extension $lo_templates->loadExtension($lo_htmlextension); // Get the view details from db if non admin if (strcasecmp($po_page->module, 'admin') === 0) { // Configure the template $la_viewdata['gs_template'] = 'templates::admin'; $la_viewdata['ga_templatedata'] = ['gs_title' => 'Mercury PHP', 'gs_currentpage' => $this->getcurrenturl(), 'gi_copyrightyear' => date('Y'), 'gs_version' => $this->getversion()]; } else { // Load any additional custom extensions $la_extensions = $this->pagemodel->getpages('VIEWEXTENSION'); foreach ($la_extensions as $lo_extension) { // Prepare the class $ls_extension = "\\Mercury\\App\\Extensions\\{$lo_extension->name}"; if (class_exists($ls_extension)) { $lo_templates->loadExtension(new $ls_extension()); } } // Get more details about template $lo_search = new \stdClass(); $lo_search->name = $ls_viewfile; $lo_search->controllerid = $po_page->controllerid; $lo_search->moduleid = $po_page->moduleid; $lo_viewdetail = $this->pagemodel->getviewdetails($lo_search); //Standard values $la_standardvals = ['gs_title' => $po_page->pagetitle, 'gs_currentpage' => $this->getcurrenturl(), 'gs_viewname' => $lo_viewdetail->name, 'gi_copyrightyear' => date('Y'), 'gs_version' => $this->getversion()]; // Configure the template $la_viewdata['gs_template'] = is_object($lo_viewdetail) && !empty($lo_viewdetail->template) ? 'templates::' . strtolower($lo_viewdetail->template) : 'defaults::blank'; $la_viewdata['ga_templatedata'] = array_merge($la_templatedata, $la_standardvals); } // Add folders used for the engine $lo_templates->addFolder('templates', $ls_templatefolder); $lo_templates->addFolder('defaults', $this->defaulttemplate); if (file_exists($ls_partialfolder)) { $lo_templates->addFolder('partials', $ls_partialfolder); } // Render the view if exists $ls_pagecontent = $lo_templates->render($ls_viewfile, $la_viewdata); // Output the page echo $ls_pagecontent; return true; }