/** * Build response body by combining data with templates * * @param View|null $view * @return string */ public function show(View $view = null) { $body = ''; if (defined('VIEW_INITIALIZED') && $view) { if ($view->get_template() === '') { $view->set_template($this->default_template); } $body = $view->apply_template(true); $this->get_response()->set_body($body); } return $body; }
public function test_render_template() { FlickrSearch\View::Initialize(realpath(__DIR__ . DIRECTORY_SEPARATOR . '..') . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'views'); $view = new FlickrSearch\View('test'); $data = array('test' => 'test1'); $view->set_data($data); $view->set_var('test2', 'test22'); $result = $view->apply_template(); $this->assertEquals($view->get_template(), 'test'); $this->assertEquals($view->get_data(), array('test' => 'test1', 'test2' => 'test22')); $this->assertEquals($result, 'test1'); $view->set_template('test2'); $this->assertEquals($view->get_template(), 'test2'); }