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
$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);
}
), $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'));
}
}