Last active
December 29, 2015 07:59
-
-
Save lukasni/7639990 to your computer and use it in GitHub Desktop.
A basic example of using Mustache subtemplates.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>{{page_title}}</title> | |
</head> | |
<body> | |
{{{content}}} | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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