浏览代码

[Templating] added Engine::exists()

Fabien Potencier 15 年之前
父节点
当前提交
478fcca88d
共有 1 个文件被更改,包括 22 次插入0 次删除
  1. 22 0
      src/Symfony/Component/Templating/Engine.php

+ 22 - 0
src/Symfony/Component/Templating/Engine.php

@@ -123,6 +123,28 @@ class Engine implements \ArrayAccess
         return $content;
     }
 
+    /**
+     * Returns true if the template exists.
+     *
+     * @param string $name A template name
+     *
+     * @return Boolean true if the template exists, false otherwise
+     */
+    public function exists($name)
+    {
+        list($tpl, $options) = $this->splitTemplateName($name);
+
+        $template = $this->loader->load($tpl, $options);
+
+        if (false === $template) {
+            return false;
+        }
+
+        $this->cache[$name] = array($tpl, $options, $template);
+
+        return true;
+    }
+
     /**
      * Outputs a rendered template.
      *