@@ -10,19 +10,34 @@ namespace Zend\Expressive\Template;
1010interface TemplateInterface
1111{
1212 /**
13+ * Render a template, optionally with parameters.
14+ *
15+ * Implementations MUST support the `namespace::template` naming convention,
16+ * and allow omitting the filename extension.
17+ *
1318 * @param string $name
1419 * @param array|object $params
1520 * @return string
1621 */
1722 public function render($name, $params = []);
1823
1924 /**
25+ * Add a template path to the engine.
26+ *
27+ * Adds a template path, with optional namespace the templates in that path
28+ * provide.
29+ *
2030 * @param string $path
2131 * @param string $namespace
2232 */
2333 public function addPath($path, $namespace = null);
2434
2535 /**
36+ * Add a template path to the engine.
37+ *
38+ * Adds a template path, with optional namespace the templates in that path
39+ * provide.
40+ *
2641 * @return TemplatePath[]
2742 */
2843 public function getPaths();
@@ -34,13 +49,19 @@ interface TemplateInterface
3449> Unfortunately, namespace syntax varies between different template engine
3550> implementations. As an example:
3651>
37- > - Plates uses the syntax ` namespace::template `
38- > - Twig uses the syntax ` @namespace/template `
39- > - zend-view does not natively support namespaces; we mimic it using normal
40- > directory syntax .
52+ > - Plates uses the syntax ` namespace::template ` .
53+ > - Twig uses the syntax ` @namespace/template ` .
54+ > - zend-view does not natively support namespaces, though custom resolvers
55+ > can provide the functionality .
4156>
42- > As such, it's not entirely possible to have engine-agnostic templates if you
43- > use namespaces.
57+ > To make different engines compatible, we require implementations to support
58+ > the syntax ` namespace::template ` (where ` namespace:: ` is optional) when
59+ > rendering. Additionally, we require that engines allow omitting the filename
60+ > suffix.
61+ >
62+ > When using a ` TemplateInterface ` implementation, feel free to use namespaced
63+ > templates, and to omit the filename suffix; this will make your code portable
64+ > and allow it to use alternate template engines.
4465
4566
4667## Paths
@@ -53,10 +74,10 @@ the actual template. You may use the `addPath()` method to do so:
5374$template->addPath('templates');
5475```
5576
56- Many template engines further allow * namespacing * templates; when adding a path,
57- you specify the template * namespace * that it fulfills, and the engine will only
58- return a template from that path if the namespace provided matches the namespace
59- for the path.
77+ Template engines adapted for zend-expressive are also required to allow
78+ * namespacing * templates; when adding a path, you specify the template
79+ * namespace * that it fulfills, and the engine will only return a template from
80+ that path if the namespace provided matches the namespace for the path.
6081
6182``` php
6283// Resolves to a path registered with the namespace "error";
@@ -81,9 +102,13 @@ of a template as the first argument:
81102$content = $template->render('foo');
82103```
83104
84- One key reason to use templates, however, is to dynamically provide data to
85- inject in the template. You may do so by passing either an associative array or
86- an object as the second argument to ` render() ` :
105+ You can specify a namespaced template using the syntax ` namespace::template ` ;
106+ the ` template ` segment of the template name may use additional directory
107+ separators when necessary.
108+
109+ One key reason to use templates is to dynamically provide data to inject in the
110+ template. You may do so by passing either an associative array or an object as
111+ the second argument to ` render() ` :
87112
88113``` php
89114$content = $template->render('message', [
0 commit comments