changed notation of namespaced templates to @namespace/template_path

This commit is contained in:
Fabien Potencier
2012-07-14 22:05:02 +02:00
parent 0eb4d01d92
commit c34541dfb3
3 changed files with 9 additions and 5 deletions
+2 -2
View File
@@ -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
+6 -2
View File
@@ -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);
}
+1 -1
View File
@@ -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'));
}
}