-1

There are so many template engines out there. However, I am looking for something simple, fast and easy like the the phpBB3.0 Template System. Something simple like

$template->set_filenames(array(
'body' => 'your_template_file.html'

));

With similar templates using {L_SOME_VARIABLE} like output. I do not want to install phpbb because of the overhead. I need it to be simple but smart enough to where if I want to output json it will recognize when the last attribute is done not to output the leading ';'

I will be using it to output data in json, xml, txt, AOML and others pointing to its respective template, depending on the choice the user makes for desired data input.

I have looked at things like Smarty, but it seems a little much for me and there doesn't seem to be any easy json solutions.

If anyone has any simple solutions please let me know. I am unable to find this exact question on here.

4

1 回答 1

1

PHP 本身是一个模板引擎(目前您可以使用它做更多事情,但基本上它是模板引擎) - 恕我直言,在模板引擎中创建和使用模板引擎有点愚蠢;)

我的建议是这样的:

function renderTemplate($_file_, $_args_ = null, $_return_ = false) {
    if (is_array($_args_)) {
        extract($_args_, EXTR_SKIP);
    }
    if ($_return_) {
        ob_start();
        ob_implicit_flush(false);
        require('/mypath/to/templates/'.$_file_.'.php');
        return ob_get_clean();
    } else {
        require('/mypath/to/templates/'.$_file_.'.php');
    }
}
于 2013-03-10T01:21:48.360 回答