Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is an example of how the php implementation of Mustache works. Of note is that Mustache.php will <strong>not</strong> expand the included partials/templates, so you have to hand them to mustache as seen below. This example was pieced together on an older cakephp framework.</p> <pre><code>&lt;? # php cannot recognize multiple acceptable file extensions for partials, # so toggle it to mustache's extension $this-&gt;ext = '.mustache'; # Mustache says it's logic-less, but that's not exactly true. # Render out the basic header which calls the logo partial and has # a {{# logged_in? }} condition which dictates which user box we # show. Thus, we need to render out the html for both the logged in # and logged out user boxes $basic_header_html = $this-&gt;renderElement('basic_header'); $logo = $this-&gt;renderElement('shared/logo'); $logged_in = $this-&gt;renderElement('shared/logged_in_user_box'); $logged_out = $this-&gt;renderElement('shared/logged_out_user_box'); $m = new Mustache($basic_header_html, array('logged_in?' =&gt; !empty($this-&gt;Auth-&gt;userData), 'cache_buster' =&gt; time(), 'display_name' =&gt; 'StackOverflow Customer'), array('shared/logo' =&gt; $logo, 'shared/logged_in_user_box' =&gt; $logged_in, 'shared/logged_out_user_box' =&gt; $logged_out)); ?&gt; &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Mustache Test&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;?= $m-&gt;render(); ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>basic_header.mustache</strong></p> <pre><code>&lt;div id="header" class="basic"&gt; {{&gt; shared/logo }} {{# logged_in? }} {{&gt; shared/logged_in_user_box }} {{/ logged_in? }} {{^ logged_in? }} {{&gt; shared/logged_out_user_box }} {{/ logged_in? }} &lt;/div&gt; </code></pre> <p><strong>shared/logo.mustache</strong></p> <pre><code>&lt;a class="logo" href="/foo/bar"&gt;&lt;img alt="" src="/images/logo.png?{{ cache_buster }}" /&gt;&lt;/a&gt; </code></pre> <p><strong>shared/logged_in_user_box.mustache</strong></p> <pre><code>Hello {{display_name}}, you are logged in. </code></pre> <p><strong>shared/logged_out_user_box.mustache</strong></p> <pre><code>Hello. You are not logged in. </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload