我刚刚开始研究使用 Mustache.php(在听到有关该库的好消息之后)。但是查看文档,您似乎必须将 HTML 模板代码存储在 PHP 变量中,以便 Mustache 能够访问它 - 这对我来说似乎很混乱,所以我想找到另一种方法来做到这一点(例如 file_get_contents 的纯 .html 文件)。
这是我正在搞乱的代码......
$template = '
<p>Hello {{name}}</p>
<p>Sorry, you\'re a {{type}}!</p>
{{#under_18}}
<p><strong><u>{{generate_random_stuff}}</u></strong>.<p>
{{/under_18}}
';
......所以相反,我认为这对我们的前端开发人员来说更容易管理......
$template = file_get_contents('template.html');
...其中'template.html'仅包含...
<p>Hello {{name}}</p>
<p>Sorry, you're a {{type}}!</p>
{{#under_18}}
<p><strong><u>{{generate_random_stuff}}</u></strong>.<p>
{{/under_18}}
但我不确定使用 file_get_contents 的效率如何?与在变量中存储为字符串相比?尤其是在多个页面视图或在单个页面上有多个模板 html 文件时。
你能给我的关于这类东西的任何信息,我将不胜感激。