gam-tpl


A simple template engine with PHP

``` // Sets the path of templates. If nuls asumes file is absolute Tpl::singleton()->setConf(Tpl::TPL_DIR, realpath(dirname(FILE))); echo Tpl::singleton()->init('demo1.phtml')->render(array( 'var1' => 1, 'var2' => 2, 'var3' => array(1, 2, 3, 4, 5, 6, 7) ));

// The same instance a different template and params added in a different way $tpl = Tpl::singleton()->init('demo2.phtml'); $tpl->addParam('header', 'header'); $tpl->addParam('footer', 'footer'); echo $tpl->render();

// Disable exceptions if we don't assign a variable Tpl::singleton()->setConf(Tpl::THROW_EXCEPTION_WITH_PARAMS, false); $tpl = Tpl::singleton()->init('demo1.phtml'); $tpl->addParam('var1', 'aaaa'); $tpl->addParam('var3', array(1, 2, 3, 4, 5, 6, 7)); echo $tpl->render();

// Using factory $objTpl = Tpl::factory(); $objTpl->setConf(Tpl::THROW_EXCEPTION_WITH_PARAMS, true); try { $tpl = $objTpl->init('demo1.phtml'); $tpl->addParam('var1', 'aaaa'); $tpl->addParam('var3', array(1, 2, 3, 4, 5, 6, 7)); echo $tpl->render(); } catch (Exception $e) { echo "

" . $e->getMessage() . "

"; } ```

Project Information

Labels:
php tpl template