Skip to content

Instantly share code, notes, and snippets.

@uppfinnarjohnny
Created December 15, 2011 15:44
Show Gist options
  • Save uppfinnarjohnny/1481559 to your computer and use it in GitHub Desktop.
Save uppfinnarjohnny/1481559 to your computer and use it in GitHub Desktop.
class Tag {
public $name;
public $contents;
public function __construct($name, $contents = array()) {
$this->name = $name;
$this->contents = $contents;
}
public function has_contents() {
return ! empty($this->contents);
}
}
$view = array(
'tags' => array(
new Tag('some_tag', array()),
new Tag('another_tag', array('value1', 'value2'))
)
);
$template = <<<EOT
<li>
{{#tags}}
<li>{{name}}</li>
{{#has_contents}}
<ol>
{{#contents}}
<li>{{.}}</li>
{{/contents}}
</ol>
{{/has_contents}}
{{/tags}}
</li>
EOT;
$m = new Mustache($template, $view);
echo $m->render();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment