Skip to content

blerou/greebo_mustache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Mustache implementation for Greebo project

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages