From c34541dfb363a60643267e855a1d088ae43a8b96 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 14 Jul 2012 22:05:02 +0200 Subject: [PATCH] changed notation of namespaced templates to @namespace/template_path --- doc/api.rst | 4 ++-- lib/Twig/Loader/Filesystem.php | 8 ++++++-- test/Twig/Tests/Loader/FilesystemTest.php | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) 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')); } } -- 1.7.2.5