Skip to content

Instantly share code, notes, and snippets.

@jinwei233
Created September 17, 2011 13:13
Show Gist options
  • Save jinwei233/1223922 to your computer and use it in GitHub Desktop.
Save jinwei233/1223922 to your computer and use it in GitHub Desktop.
mustache php 模板解析
<?php
require_once("../../app/tpl-engine/mustache.php/Mustache.php");
///////////////////////////////////////////simple Hello world//////////////////////////////
$m = new Mustache;
echo $m->render('Hello {{planet}}', array('planet' => 'World!'));
// "Hello World!"
///////////////////////////////////////////use class //////////////////////////////
class Chris extends Mustache {
public $name = "Chris";
public $value = 10000;
public function taxed_value() {
return $this->value - ($this->value * 0.4);
}
public $in_ca = true;
}
$template = '
Hello {{name}}
You have just won ${{value}}!
{{#in_ca}}
Well, ${{taxed_value}}, after taxes.
{{/in_ca}}
';
$c = new Chris;
echo $c->render($template);
///////////////////////////////////////////use class2 //////////////////////////////
class Chris2 {
public $name = "Chris";
public $value = 10000;
public function taxed_value() {
return $this->value - ($this->value * 0.4);
}
public $in_ca = true;
}
$chris = new Chris2;
$m = new Mustache;
echo $m->render($template, $chris);
///////////////////////////////////////////use file tempate //////////////////////////////
$template = file_get_contents("mustache.html");
echo $m->render($template,$chris);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment