From: Fabien Potencier Date: Sat, 14 Jul 2012 20:05:02 +0000 (+0200) Subject: changed notation of namespaced templates to @namespace/template_path X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=c34541dfb363a60643267e855a1d088ae43a8b96;p=web%2Fkonrad%2Ftwig.git changed notation of namespaced templates to @namespace/template_path --- diff --git a/doc/api.rst b/doc/api.rst index 3a49129..1f8e1fc 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -151,11 +151,11 @@ methods:: The filesystem loader also supports namespaced templates. This allows to divide your templates in different namespaces; each namespace having its own template paths. Namespaced templates can be accessed via the special -``namespace_name#template_path`` notation:: +``@namespace_name/template_path`` notation:: $loader->addPath($templateDir, 'admin'); - $twig->render('admin#index.html', array()); + $twig->render('@admin/index.html', array()); The ``setPaths()``, ``addPath()``, and ``prependPath()`` methods all takes a namespace as an optional second argument; when not specified, these methods diff --git a/lib/Twig/Loader/Filesystem.php b/lib/Twig/Loader/Filesystem.php index 7def513..2be0d90 100644 --- a/lib/Twig/Loader/Filesystem.php +++ b/lib/Twig/Loader/Filesystem.php @@ -143,8 +143,12 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface $this->validateName($name); $namespace = ''; - if (false !== $pos = strpos($name, '#')) { - $namespace = substr($name, 0, $pos); + if (isset($name[0]) && '@' == $name[0]) { + if (false === $pos = strpos($name, '/')) { + throw new \InvalidArgumentException(sprintf('Malformed template name "%s".', $name)); + } + + $namespace = substr($name, 1, $pos - 1); $name = substr($name, $pos + 1); } diff --git a/test/Twig/Tests/Loader/FilesystemTest.php b/test/Twig/Tests/Loader/FilesystemTest.php index 28b5d18..ffc4fb7 100644 --- a/test/Twig/Tests/Loader/FilesystemTest.php +++ b/test/Twig/Tests/Loader/FilesystemTest.php @@ -75,6 +75,6 @@ class Twig_Tests_Loader_FilesystemTest extends PHPUnit_Framework_TestCase ), $loader->getPaths('named')); $this->assertEquals("path (final)\n", $loader->getSource('index.html')); - $this->assertEquals("named path (final)\n", $loader->getSource('named#index.html')); + $this->assertEquals("named path (final)\n", $loader->getSource('@named/index.html')); } }