gpt4 book ai didi

php - 在模板 Mustache.php 中包含模板

转载 作者:可可西里 更新时间:2023-11-01 00:32:52 25 4
gpt4 key购买 nike

我有 3 个模板文件:

main.tpl
main_header.tpl
main_footer.tpl

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

我该怎么办?

最佳答案

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

{{> 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);

关于php - 在模板 Mustache.php 中包含模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20289059/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com