Renderer options #642

Closed
wants to merge 2 commits into
from
View
@@ -133,6 +133,14 @@
protected $_vars = array();
/**
+ * Available options accepted by `template\View::render()`, used when rendering.
+ *
+ * @see lithium\template\View::render()
+ * @var array
+ */
+ protected $_options = array();
+
+ /**
* Render the template with given data. Abstract; must be added to subclasses.
*
* @param string $template
@@ -486,10 +494,7 @@ public function set(array $data = array()) {
* @return string Returns a the rendered template content as a string.
*/
protected function _render($type, $template, array $data = array(), array $options = array()) {
- if ($this->_request) {
- $library = $this->_request->library;
- $options += compact('library');
- }
+ $options += $this->_options;
return $this->_view->render($type, $data + $this->_data, compact('template') + $options);
}
}
@@ -102,6 +102,8 @@ public function render($template, $data = array(), array $options = array()) {
$this->_context = $options['context'] + $this->_context;
$this->_data = (array) $data + $this->_vars;
+ $this->_options = $options;
+
$template__ = $template;
unset($options, $template, $defaults, $data);
@@ -175,6 +175,38 @@ public function testNolayout() {
unset($renderData[0]['data']['h']);
$this->assertEqual($expected, $renderData);
}
+
+ public function testElementRendering() {
+ $view = new View(array(
+ 'loader' => 'lithium\tests\mocks\template\view\adapters\TestRenderer',
+ 'paths' => array(
+ 'template' => '{:library}/tests/mocks/template/view/adapters/{:template}.html.php',
+ 'element' => array(
+ '{:library}/tests/mocks/template/view/adapters/{:controller}/_{:template}.html.php',
+ '{:library}/tests/mocks/template/view/adapters/{:template}.html.php'
+
+ ),
+ 'layout' => false
+ )
+ ));
+
+ $options = array(
+ 'template' => 'testElement',
+ 'library' => LITHIUM_LIBRARY_PATH . '/lithium'
+ );
+ $result = $view->render('all', array(), $options);
+ $expected = 'This is a rendered element';
+ $this->assertEqual($expected, $result);
+
+ $options = array(
+ 'template' => 'testElement',
+ 'library' => LITHIUM_LIBRARY_PATH . '/lithium',
+ 'controller' => 'posts'
+ );
+ $result = $view->render('all', array(), $options);
+ $expected = 'This is a rendered _element';
+ $this->assertEqual($expected, $result);
+ }
}
?>
@@ -0,0 +1 @@
+element
@@ -0,0 +1 @@
+This is a rendered <?= $this->_render('element', 'elementFile'); ?>