public function test_set() { $ootemplate = new OOTemplate(); $context = $ootemplate->getContext(); $user_object = new stdClass(); $user_object->nickname = 'foobar'; $res = $ootemplate->set('user', $user_object); $this->assertTrue($res instanceof OOTemplate_Context); $this->assertTrue(is_object($context->user)); $this->assertEqual($context->user->nickname, 'foobar'); $user_array = array(); $user_array['nickname'] = 'foobar'; $res = $ootemplate->set('user', $user_object); $this->assertTrue($res instanceof OOTemplate_Context); $this->assertTrue(is_object($context->user)); $this->assertEqual($context->user->nickname, 'foobar'); }
<?php ini_set('include_path', ini_get('include_path') . ':' . dirname(__FILE__) . '/../lib:'); require 'OOTemplate.php'; $t = new OOTemplate(new OOTemplate_Document('<html>Hello {% if who %} {{ who | upper }} {% endif %}</html>')); echo $t->render() . "\n"; // output: // <html>Hello </html> $c = $t->getContext(); $c->who = 'World'; echo $t->render() . "\n"; // output: // <html>Hello World</html>