Skip to content

Latest commit

 

History

History
75 lines (48 loc) · 1.96 KB

README.markdown

File metadata and controls

75 lines (48 loc) · 1.96 KB

Greebo Mustache

Build Status

A Mustache implementation in PHP.

Usage

A quick example:

<?php
	// simple construct
	$mustache = Mustache::create(TEMPLATE_PATH);

	// advanced construct
	$loader = new TemplateLoader();
	$loader->addTemplatePath(TEMPLATE_PATH);
	$mustache = new Mustache(new JitRenderer($loader));

	echo $mustache->render(TEMPLATE_NAME, array('planet' => 'World!'));
// "Hello World!"
?>

And a more in-depth example--this is the canonical Mustache template (chris.mustache on template path):

Hello {{name}}
You have just won ${{value}}!
{{#in_ca}}
Well, ${{taxed_value}}, after taxes.
{{/in_ca}}

Along with the associated Mustache class:

<?php
class Chris {
    public $name = "Chris";
    public $value = 10000;

    public function taxed_value() {
        return $this->value - ($this->value * 0.4);
    }

    public $in_ca = true;
}

Render it like so:

<?php
	$mustache = Mustache::create(TEMPLATE_PATH_TO_CHRIS);

	echo $mustache->render('chris', new Chris());
?>

It's different

Other mustache implementations in PHP parses and interpret templates on-the-fly. It's a very time consuming task. This implementation "generates" PHP template from .mustache file and then run in the given "context".

See Also