added the possibility to pass a readable name for templates
authorFabien Potencier <fabien.potencier@gmail.com>
Fri, 4 Feb 2011 11:46:05 +0000 (12:46 +0100)
committerFabien Potencier <fabien.potencier@gmail.com>
Fri, 4 Feb 2011 11:53:35 +0000 (12:53 +0100)
lib/Twig/Environment.php

index 92809ed..321de23 100644 (file)
@@ -272,12 +272,17 @@ class Twig_Environment
     /**
      * Loads a template by name.
      *
-     * @param  string  $name  The template name
+     * @param string $name  The template name
+     * @param string $short The template name to use for error messages
      *
      * @return Twig_TemplateInterface A template instance representing the given template name
      */
-    public function loadTemplate($name)
+    public function loadTemplate($name, $short = null)
     {
+        if (null === $short) {
+            $short = $name;
+        }
+
         $cls = $this->getTemplateClass($name);
 
         if (isset($this->loadedTemplates[$cls])) {
@@ -286,10 +291,10 @@ class Twig_Environment
 
         if (!class_exists($cls, false)) {
             if (false === $cache = $this->getCacheFilename($name)) {
-                eval('?>'.$this->compileSource($this->loader->getSource($name), $name));
+                eval('?>'.$this->compileSource($this->loader->getSource($name), $short));
             } else {
                 if (!file_exists($cache) || ($this->isAutoReload() && !$this->loader->isFresh($name, filemtime($cache)))) {
-                    $this->writeCacheFile($cache, $this->compileSource($this->loader->getSource($name), $name));
+                    $this->writeCacheFile($cache, $this->compileSource($this->loader->getSource($name), $short));
                 }
 
                 require_once $cache;