我知道问这个问题已经有一段时间了,但为了记录,我想指出一个聪明的特点,我认为这是行动要求的。下面是我的应用程序中的一部分代码。
基本上它所做的就是首先在
/ext/templates
. 如果在那里找不到它,它将使用来自
/base/templates
. 我的代码只需要一个回退,但更容易添加。
class View extends Smarty {
function __construct() {
parent::Smarty();
$this->template_dir = LOCAL_APP_ROOT.'/ext/templates';
$this->compile_dir = LOCAL_APP_ROOT.'/cache/compile';
$this->default_template_handler_func = '__default_template_handler';
}
}
function __default_template_handler($resource_type, $resource_name, &$template_source, &$template_timestamp, &$smarty_obj) {
if ($resource_type == 'file') {
if (!is_readable($resource_name)) {
$defaultPath = LOCAL_APP_ROOT."/base/templates/$resource_name";
if (file_exists($defaultPath)) {
$template_source = file_get_contents($defaultPath);
$template_timestamp = filemtime($defaultPath);
return true;
}
}
}
return false;
}