我正在尝试使用 Mustache 的 PHP 实现在这样的模板中嵌入一些 html 内容:
[mytemplate begin]
[html content]
[mytemplate end]
我的 html 内容在 html 文件中,当我尝试渲染它时出现错误:
echo $template->render(array('content' => file_get_contents('content.html')));
这是错误:
致命错误:达到最大函数嵌套级别"100",正在中止! 在 C:''wamp''www''resume''application''mustache''src''Mustache''Engine.php 第 257 行
如何将其作为 html 内容插入?
section.mustache文件(我删除了很大一部分html代码,只有必不可少的)
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<!-- CONTENT -->
<div class="container">
{{> section}}
</div>
</body>
</html>
和内容.html文件(考虑到他们的是另外两个<section>
,代码量相同)
<div class="section">
<!-- Icon Section -->
<div class="row">
<div class="col s12 m8 offset-m2 l8 offset-l2">
<section id="sports" class="section scrollspy">
<h1>Sports</h1>
<div class="card">
<div class="card-image waves-effect waves-block waves-light">
<img src="media/images/climbing.jpg">
</div>
<div class="card-content">
<span class="card-title activator grey-text text-darken-4">Escalade<i class="mdi-navigation-more-vert right"></i></span>
</div>
<div class="card-reveal z-depth-3">
<span class="card-title grey-text text-darken-4"><h4>Escalade</h4><i class="mdi-navigation-close right"></i></span>
<p class="flow-text">Here is some more information about this product that is only revealed once clicked on. </p>
</div>
</div>
<div class="card">
<div class="card-image waves-effect waves-block waves-light">
<img src="media/images/snowboard.jpg">
</div>
<div class="card-content">
<span class="card-title activator grey-text text-darken-4">Snowboard<i class="mdi-navigation-more-vert right"></i></span>
</div>
<div class="card-reveal">
<span class="card-title grey-text text-darken-4"><h4>Snowboard</h4><i class="mdi-navigation-close right"></i></span>
<p class="flow-text">Here is some more information about this product that is only revealed once clicked on.</p>
</div>
</div>
</section>
</div>
<div class="col hide-on-small-only s12 m2 l1">
<div style="height: 1px;">
<ul class="section table-of-contents pinned" style="top: 0px;">
<li><a href="#sports" class="">Sports</a></li>
</ul>
</div>
</div>
</div>
</div>
你在命名中有点迷茫。胡子正要猜测它的名字要包含哪个模板。可是
{{> section}}
包括section.mustache
.由于它出现在您的section.mustache
中,引擎会尝试递归地将其插入到自身中。这显然会导致无限循环,该循环在嵌套级别 100 终止,并收到错误。
您应该将content.html
重命名为content.mustache
并包含以下内容:
{{> content}}
希望对您有所帮助。