mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-14 11:27:00 +00:00
changed notation of namespaced templates to @namespace/template_path
This commit is contained in:
+2
-2
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user