Bạn có thể dễ dàng thực hiện việc này bằng cách thêm triển khai trình tải phần bổ sung mới. Bạn có thể thực hiện một "bí danh loader", mà các cửa hàng những tài liệu tham khảo mẫu:
class FilesystemAliasLoader extends Mustache_Loader_FilesystemLoader implements Mustache_Loader_MutableLoader
{
private $aliases = array();
public function __construct($baseDir, array $aliases = array())
{
parent::__construct($baseDir);
$this->setTemplates($aliases);
}
public function load($name)
{
if (!isset($this->aliases[$name])) {
throw new Mustache_Exception_UnknownTemplateException($name);
}
return parent::load($this->aliases[$name]);
}
public function setTemplates(array $templates)
{
$this->aliases = $templates;
}
public function setTemplate($name, $template)
{
$this->aliases[$name] = $template;
}
}
Sau đó, bạn sẽ thiết lập đó là partials loader:
$partials = array(
'sidebar' => 'folder1/somefile'
);
$mustache = new Mustache_Engine(array(
'loader' => new Mustache_Loader_FilesystemLoader('path/to/templates'),
'partials_loader' => new FilesystemAliasLoader('path/to/partials'),
'partials' => $partials,
));
... hoặc bạn có thể vượt qua các bí danh đến trình tạo bộ tải hoặc bạn thậm chí có thể đặt chúng sau này trên trình tải hoặc công cụ động cơ:
$loader = new FilesystemAliasLoader('path/to/partials', $partials);
$loader->setTemplates($partials);
$mustache->setPartials($partials);
Tôi là AFK trong vài ngày qua. Cảm ơn câu trả lời của bạn, đây là những gì tôi đang tìm kiếm! – feketegy