Lightweight PHP5 based template class/system

后端 未结 6 2114
遥遥无期
遥遥无期 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:57

    I believe the PHP itself is a very powerful template engine.

    If you just need a very simple template engine, you can wrap a str_replace(), for example:

    function template($source, array $vars, $return=false) {
        foreach ($vars as $key=>$value) {
            $source = str_replace('{'.$key.'}', $value, $source);
        }
        if ($return) {
            return $source;
        } else {
            echo $source;
        }
    }
    

    And there is a simple yet flexible template engine from symfony if you need a full featured solution.

提交回复
热议问题