在模板Mustache.php中包含模板

时间:2013-11-29 15:31:41

标签: php mustache

我有3个模板文件:

main.tpl
main_header.tpl
main_footer.tpl

我需要使用Mustache.php将最后2个模板包含在第一个模板中 我找不到有关它的文档。

我该怎么办?

1 个答案:

答案 0 :(得分:6)

包含的模板在Mustache中称为“partials”。包含它们的标记如下所示:

{{> main_header }}
{{> main_footer }}

您需要set up a template loader以便Mustache可以自动加载它们。

由于您的文件扩展名为.tpl,因此您还应let your template loader know

结果代码可能如下所示:

<?php

$m = new Mustache_Engine(array(
    'loader' => new Mustache_Loader_FilesystemLoader(
        __DIR__.'/path/to/views',
        array('extension' => '.tpl')
    ),
));

echo $m->render('main', $data);
相关问题