예제 #1
0
 public function testIncludePath()
 {
     // no include path
     $tpl = new Dwoo_Template_File('test.html');
     $this->assertEquals('test.html', $tpl->getResourceIdentifier());
     // include path in constructor
     $tpl = new Dwoo_Template_File('test.html', null, null, null, TEST_DIRECTORY . DIRECTORY_SEPARATOR . 'resources');
     $this->assertEquals(TEST_DIRECTORY . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'test.html', $tpl->getResourceIdentifier());
     // set include path as string
     $tpl->setIncludePath(TEST_DIRECTORY . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'subfolder' . DIRECTORY_SEPARATOR);
     $this->assertThat($tpl->getResourceIdentifier(), new DwooConstraintPathEquals(TEST_DIRECTORY . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'subfolder' . DIRECTORY_SEPARATOR . 'test.html'));
     // set include path as array
     $tpl->setIncludePath(array(TEST_DIRECTORY . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'subfolder2', TEST_DIRECTORY . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'subfolder' . DIRECTORY_SEPARATOR));
     $this->assertThat($tpl->getResourceIdentifier(), new DwooConstraintPathEquals(TEST_DIRECTORY . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'subfolder2' . DIRECTORY_SEPARATOR . 'test.html'));
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function render($viewName, Model $model, NotificationCenter $notificationCenter, $output = true)
 {
     Profile::start('Renderer', 'Generate HTML');
     $templateName = $viewName . '.' . static::$templateFileExtension;
     $dwoo = new Dwoo($this->compiledPath, $this->cachePath);
     $dwoo->getLoader()->addDirectory($this->functionsPath);
     Profile::start('Renderer', 'Create template file.');
     $template = new Dwoo_Template_File($templateName);
     $template->setIncludePath($this->getTemplatesPath());
     Profile::stop();
     Profile::start('Renderer', 'Render');
     $dwooData = new Dwoo_Data();
     $dwooData->setData($model->getData());
     $dwooData->assign('errorMessages', $notificationCenter->getErrors());
     $dwooData->assign('successMessages', $notificationCenter->getSuccesses());
     $this->setHeader('Content-type: text/html', $output);
     // I do never output directly from dwoo to have the possibility to show an error page if there was a render error.
     $result = $rendered = $dwoo->get($template, $dwooData, null, false);
     if ($output) {
         echo $result;
     }
     Profile::stop();
     Profile::stop();
     return $output ? null : $rendered;
 }