我刚开始使用Mustache.php,我正在寻找一种方法来向我的Mustache.php加载器添加一个覆盖功能,就像在Joomla中使用的那样。
我正在从“视图”目录加载部分内容,我想告诉Mustache首先读取存储在“覆盖”中的部分,然后,如果在该文件夹中找不到部分,请在“views”文件夹。
目前我正在使用此代码加载我的部分内容:
// Mustache templates path
$mustache_tpls = $_SERVER['BASE_DIR'] . '/views';
// Mustache options
$mustache_opts = array('extension' => '.tpl');
// Mustache cache path
$mustache_cache = $_SERVER['BASE_DIR'] . '/tmp/cache/views';
// Init Mustache engine
$m = new Mustache_Engine(
array(
'cache' => $mustache_cache,
'loader' => new Mustache_Loader_FilesystemLoader(
$mustache_tpls,
$mustache_opts
)
)
);
我该怎么办?
答案 0 :(得分:1)
您正在寻找the CascadingLoader:
// Mustache templates paths
$mustache_tpls = $_SERVER['BASE_DIR'] . '/views';
$mustache_override_tpls = $_SERVER['BASE_DIR'] . '/overrides';
// Mustache options
$mustache_opts = array('extension' => '.tpl');
// Mustache cache path
$mustache_cache = $_SERVER['BASE_DIR'] . '/tmp/cache/views';
// Cascading template loader
$mustache_loader = new Mustache_Loader_CascadingLoader(array(
new Mustache_Loader_FilesystemLoader($mustache_override_tpls, $mustache_opts),
new Mustache_Loader_FilesystemLoader($mustache_tpls, $mustache_opts),
));
// Init Mustache engine
$m = new Mustache_Engine(
array(
'cache' => $mustache_cache,
'loader' => $mustache_loader
)
);