小胡子PHP 把模板放在模板里
Mustache PHP Put a template in a template
我正在尝试使用 Mustache 的 PHP 实现在模板中嵌入一些 html 内容,如下所示:
[mytemplate begin]
[html content]
[mytemplate end]
我的 html 内容在 html 文件中,当我尝试渲染它时出现错误:
echo $template->render(array('content' => file_get_contents('content.html')));
这是错误:
Fatal error: Maximum function nesting level of '100' reached, aborting! in C:\wamp\www\resume\application\mustache\src\Mustache\Engine.php on line 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>
和 content.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>
你有点迷失了命名。 Mustache 即将根据名称猜测要包含哪个模板。也就是说,
{{> section}}
包括section.mustache
。由于它出现在您的 section.mustache
中,引擎会尝试以递归方式将其插入自身。这显然会导致无限循环,它在嵌套级别 100 处终止,并出现您收到的错误。
您应该将 content.html
重命名为 content.mustache
并包含以下内容:
{{> content}}
希望对您有所帮助。
我正在尝试使用 Mustache 的 PHP 实现在模板中嵌入一些 html 内容,如下所示:
[mytemplate begin]
[html content]
[mytemplate end]
我的 html 内容在 html 文件中,当我尝试渲染它时出现错误:
echo $template->render(array('content' => file_get_contents('content.html')));
这是错误:
Fatal error: Maximum function nesting level of '100' reached, aborting! in C:\wamp\www\resume\application\mustache\src\Mustache\Engine.php on line 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>
和 content.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>
你有点迷失了命名。 Mustache 即将根据名称猜测要包含哪个模板。也就是说,
{{> section}}
包括section.mustache
。由于它出现在您的 section.mustache
中,引擎会尝试以递归方式将其插入自身。这显然会导致无限循环,它在嵌套级别 100 处终止,并出现您收到的错误。
您应该将 content.html
重命名为 content.mustache
并包含以下内容:
{{> content}}
希望对您有所帮助。