public function load($name)
 {
     if (!isset($this->aliases[$name])) {
         throw new Mustache_Exception_UnknownTemplateException($name);
     }
     return parent::load($this->aliases[$name]);
 }
Пример #2
0
 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)
 }
 /**
  * Constructor.
  *
  * @param FileLocatorInterface        $locator A FileLocatorInterface instance
  * @param TemplateNameParserInterface $parser  A TemplateNameParserInterface instance
  */
 public function __construct(FileLocatorInterface $locator, TemplateNameParserInterface $parser)
 {
     parent::__construct(array());
     $this->locator = $locator;
     $this->parser = $parser;
     $this->cache = array();
 }
 /**
  * Helper function for getting a Mustache template file name.
  * Strips the leading component as we are already limited to the correct directories.
  *
  * @param string $name
  *
  * @return string Template file name
  */
 protected function getFileName($name)
 {
     if (strpos($name, '/') === false) {
         throw new coding_exception('Templates names must be specified as "componentname/templatename" (' . $name . ' requested) ');
     }
     list($component, $templatename) = explode('/', $name, 2);
     return parent::getFileName($templatename);
 }
Пример #5
0
 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);
 }
 /**
  * Mustache production filesystem Loader constructor.
  *
  * Passing an $options array allows overriding certain Loader options during instantiation:
  *
  *     $options = array(
  *         // The filename extension used for Mustache templates. Defaults to '.mustache'
  *         'extension' => '.ms',
  *         'stat_props' => array('size', 'mtime'),
  *     );
  *
  * Specifying 'stat_props' overrides the stat properties used to invalidate the template cache. By default, this
  * uses 'mtime' and 'size', but this can be set to any of the properties supported by stat():
  *
  *     http://php.net/manual/en/function.stat.php
  *
  * You can also disable filesystem stat entirely:
  *
  *     $options = array('stat_props' => null);
  *
  * But with great power comes great responsibility. Namely, if you disable stat-based cache invalidation,
  * YOU MUST CLEAR THE TEMPLATE CACHE YOURSELF when your templates change. Make it part of your build or deploy
  * process so you don't forget!
  *
  * @throws Mustache_Exception_RuntimeException if $baseDir does not exist.
  *
  * @param string $baseDir Base directory containing Mustache template files.
  * @param array $options Array of Loader options (default: array())
  */
 public function __construct($baseDir, array $options = array())
 {
     parent::__construct($baseDir, $options);
     if (array_key_exists('stat_props', $options)) {
         if (empty($options['stat_props'])) {
             $this->statProps = array();
         } else {
             $this->statProps = $options['stat_props'];
         }
     } else {
         $this->statProps = array('size', 'mtime');
     }
 }
Пример #7
0
 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');
 }