dqwh1209 2015-01-18 16:38
浏览 122
已采纳

Mustache PHP将模板放入模板中

I'm trying to use the PHP implementation of Mustache to embed some html content in a template like this :

[mytemplate begin]
   [html content]
[mytemplate end]

My html content is in a html file and when I try rendering it I have an error:

echo $template->render(array('content' => file_get_contents('content.html')));

Here's the error :

Fatal error: Maximum function nesting level of '100' reached, aborting! in C:\wamp\wwwesume\application\mustache\src\Mustache\Engine.php on line 257

How can I insert it as html content ?

the section.mustache file ( I removed a huge part of the html code, there's just the essential)

<!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>

And the content.html file (Consider that there's is two other <section> with just the same amount of code)

<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>
  • 写回答

1条回答 默认 最新

  • douxian1892 2015-01-18 17:56
    关注

    You are a bit lost in namings. Mustache is about to guess which template is to be included by it’s name. That said,

    {{> section}}
    

    includes section.mustache. Since it appears in your section.mustache, the engine tries to recursively insert it into itself. Which apparently leads to infinite loop, which is terminated at nesting level 100 with an error you received.

    You should rename your content.html into content.mustache and include content:

    {{> content}}
    

    Hope it helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 武汉岩海低应变分析软件,导数据库里不显示波形图
  • ¥15 CreateBitmapFromWicBitmap内存释放问题。
  • ¥30 win c++ socket
  • ¥15 CanMv K210开发板实现功能
  • ¥15 C# datagridview 栏位进度
  • ¥15 vue3页面el-table页面数据过多
  • ¥100 vue3中融入gRPC-web
  • ¥15 kali环境运行volatility分析android内存文件,缺profile
  • ¥15 写uniapp时遇到的问题
  • ¥15 vs 2008 安装遇到问题