From f6f3d89c28e3cf7cf40f34329c2e012cdf983dd5 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 7 Aug 2011 22:17:56 -0400 Subject: [PATCH] Allow an array of variables to be passed to Template::Render() --- testing/tests/views/template_test.php | 11 +++++++++++ views/template.php | 11 +++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/testing/tests/views/template_test.php b/testing/tests/views/template_test.php index dc1e7ce..057b215 100644 --- a/testing/tests/views/template_test.php +++ b/testing/tests/views/template_test.php @@ -95,4 +95,15 @@ class TemplateTest extends \PHPUnit_Framework_TestCase } $this->assertTrue($catch); } + + public function testRenderVars() + { + $template = Template::NewWithData('Some {% $v %}'); + $this->assertEquals('Some value', $template->Render(array('v' => 'value'))); + + $template->v = 'other'; + $this->assertEquals('Some thing', $template->Render(array('v' => 'thing'))); + + $this->assertEquals('Some other', $template->Render()); + } } diff --git a/views/template.php b/views/template.php index f43e099..8814f19 100644 --- a/views/template.php +++ b/views/template.php @@ -75,17 +75,24 @@ class Template } /*! This includes the template and renders it out. */ - public function Render() + public function Render($vars = array()) { $_template = $this->data; - $_vars = $this->vars; + $_vars = array_merge($this->vars, $vars); $render = function () use ($_template, $_vars) { extract($_vars); eval('?>' . $_template . '<' . '?'); }; ob_start(); + + $error = error_reporting(); + error_reporting($error & ~E_NOTICE); + $render(); + + error_reporting($error); + $data = ob_get_contents(); ob_end_clean(); return $data; -- 2.22.5