Skip to content

Instantly share code, notes, and snippets.

@lukasni
Last active December 29, 2015 07:59
Show Gist options
  • Save lukasni/7639990 to your computer and use it in GitHub Desktop.
Save lukasni/7639990 to your computer and use it in GitHub Desktop.
A basic example of using Mustache subtemplates.
<div class="blog">
<header>
<h1>{{blog_title}}</h1>
</header>
{{#articles}}
<article class="blog-article">
<header><h2>{{title}}</h2></header>
<section class="blog-body">
{{{body}}}
</section>
</article>
{{/articles}}
</div>
<!DOCTYPE html>
<html>
<head>
<title>{{page_title}}</title>
</head>
<body>
{{{content}}}
</body>
</html>
<?php
$m = new Mustache_Engine();
$layout = $m->loadTemplate('layout');
$content= $m->loadTemplate('blog');
$view_content = [
'blog_title' => 'Foo Bar',
'articles' => [
[
'title' => 'Lipsum',
'body' => 'Lorem ipsum dolor...',
],
[
'title' => 'Bar Baz',
'body' => 'Foo Bar Baz etc...',
],
],
];
$content = $content->render($view_content);
$view_layout = [
'page_title' => 'Some inane blog',
'content' => $content;
];
echo $layout->render($view_layout);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment