public function testRenderTemplateWithCaseTag() { $tplData = array('login' => 'Toto', 'gender' => rand(1, 0)); $tplString = 'hello [if: {gender} == 1 ? Mr : Miss ] {login}, did you like parsor !'; $tplStringTest = 'hello ' . ($tplData['gender'] == 1 ? 'Mr' : 'Miss') . ' Toto, did you like parsor !'; $tpl = new BaseZF_DbTemplate(); $tpl->setTemplate($tplString); $tpl->setData($tplData); $this->assertEquals($tplStringTest, $tpl->render()); }
public function dbtemplateAction() { $examples = new MyProject_DbCollection('example'); $examples->filterWhere('example_id > ? AND example_type_id = 1', 1); $examples->filterOrderBy('example_id DESC'); $examples->filterLimit(10); $examples->filterExecute(); $data = array('titi' => rand(1, 3), 'tata' => array('tutu' => time(), 'tete' => time()), 'data' => $examples, 'data2' => array('a', 'b')); $tplString = ' <pre> test string with var name : titi test var : titi={titi} test if titi == 1 : [if: {titi} == 1 ? titi=true : titi=false] test var array assoc : {tata:tutu} test const : [const:BASE_PATH] [begin:{datas}] test begin/end with limit : {data:unique_string} [end:{datas}] </pre> '; $tpl = new BaseZF_DbTemplate(); $tpl->setTemplate($tplString); $tpl->setData($data); $tplRendered = $tpl->render(); echo $tplRendered; /* echo "<hr />"; $sleepTpl = serialize($tpl); var_dump($sleepTpl); echo "<hr />"; $wakeupTpl = unserialize($sleepTpl); var_dump($wakeupTpl); echo "<hr />"; echo $wakeupTpl; */ die; }