public function load($name) { //the template name is something like "page.index" or "layout.sidenav.items" //we check whether it's a layout or page , and depending on $this->page_name OR $this->layout_name we find the appropriate partial file $parts = explode('.', $name, 2); $type = $parts[0]; if ($type != 'page' and $type != 'layout') { return ''; } $file = str_replace('.', '/', $parts[1]); if ($type == 'page' and $file == 'content') { return parent::load("/{$type}s/{$this->page_name}.mustache"); } $item_name = $type . '_name'; $item_name = $this->{$item_name}; //page_name OR layout_name , value of current page or layout e.g. default, login | index, widgets, etc ... //look in the partials for this page or layout $path = "/{$type}s/partials/{$item_name}/{$file}.mustache"; if (!is_file($this->baseDir . $path)) { //look in the upper folder, which contains partials for all pages or layouts $path = "/{$type}s/partials/_shared/{$file}.mustache"; if (!is_file($this->baseDir . $path)) { return ''; } } return parent::load($path); //we don't use $this->baseDir.$path , because baseDir has already been passed onto parent(Mustache_Loader_FilesystemLoader) }
public function load($name) { if (!isset($this->aliases[$name])) { throw new Mustache_Exception_UnknownTemplateException($name); } return parent::load($this->aliases[$name]); }
public function load($name) { if ($this->aliases == null) { return parent::load($name); } if (array_key_exists($name, $this->aliases)) { $name = $this->aliases[$name]; } return parent::load($name); }
public function load($name) { $parts = explode('.', $name, 2); $type = $parts[0]; if ($type != 'page' and $type != 'layout') { return ''; } $file = str_replace('.', '/', $parts[1]); if ($type == 'page' and $file == 'content') { return parent::load("/{$type}s/{$this->_page_name}.mustache"); } $item_name = '_' . $type . '_name'; $item_name = $this->{$item_name}; $path = "/{$type}s/partials/{$item_name}/{$file}.mustache"; if (!is_file($this->_views_dir . $path)) { //look in the upper folder, which contains partials for all pages or layouts $path = "/{$type}s/partials/_shared/{$file}.mustache"; if (!is_file($this->_views_dir . $path)) { return ''; } } return parent::load($path); }
/** * @expectedException Mustache_Exception_UnknownTemplateException */ public function testMissingTemplateThrowsException() { $baseDir = realpath(dirname(__FILE__) . '/../../../fixtures/templates'); $loader = new Mustache_Loader_FilesystemLoader($baseDir); $loader->load('fake'); }