PHP模板引擎与PHP代码

时间:2014-05-22 23:32:11

标签: php

是的我知道他们不是这个问题的大量信息,但我正在寻找一个PHP模板引擎。我试过的每一个模板引擎都只是让我的PHP代码成为评论? (绿色)我知道它可以完成,因为我以前见过它。

我只是想检查是否使用isset

设置了登录表单

我使用

打电话给班级
    require(JBOOT_DIR_CLASSES . 'class.template.php');
    $template = new Template(JBOOT_DIR . website_theme_dir . JBOOT_DS . website_theme . JBOOT_DS . website_theme_pages_dir . JBOOT_DS . 'welcome' . JBOOT_DS . website_theme_page_contentfile_dir);
    $template->load(JBOOT_DIR . website_theme_dir . JBOOT_DS . website_theme . JBOOT_DS . website_theme_pages_dir . JBOOT_DS . 'welcome' . JBOOT_DS . website_theme_page_contentfile_dir);
    $template->params();
    $template->removeEmpty();
    echo $template->parse();

这是班级

<?php

class template
{
    public $template;
    public function __construct($template = null)
    {
        if (isset($template))
        {
            $this->load($template);
        }
    }
    public function params()
    {
        $this->set("username", "user x");
    }
    public function load($file)
    {
        if (isset($file) && file_exists($file))
        {
            $this->template = file_get_contents($file);
        }
    }
    public function set($var, $content)
    {
        $this->template = str_replace("{" . $var . "}", $content, $this->template);
    }
    public function publish()
    {
        /*
         * Prints out the theme to the page
         * However, before we do that, we need to remove every var
         * within {} that are not set
         */
        template::removeEmpty();
        eval("?>" . $this->template . "<?");
    }
    public function removeEmpty()
    {
        /*
         * This function would remove all empty variables from the template wrapped in     {}
         */
         $this->template = preg_replace('^{.*}^', "", $this->template);
    }
    public function parse()
    {
        /*
         * This function grabs a static document and returns the content
        */
        return $this->template;
    }
}
?>

0 个答案:

没有答案