Lightweight PHP5 based template class/system

后端 未结 6 2115
遥遥无期
遥遥无期 2020-12-16 03:08

Looking at using a template system for a new project, it\'s only a small site and don\'t want to use the overhead and \'complexity\' of smarty. I don\'t really like template

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-16 03:43

    simplest... just create class blocks like:

    class MyBlock implements IHtmlRenderizable{
        private $_vars = array();
        public function addVar($name, $value) { 
            $this->_vars[$name] = $value; return $this; 
        }
        public function toHtml(){
            extract($this->_vars);
            include('/the/template.phtml');
        }
    }
    

    and use $this->whatever on the template. or use:

    $block->addVar('myvar', 'myvalue')->toHtml();
    

    and on the template you can access it with $myvar

提交回复
热议问题