2011-02-24 22:26:09 +02:00
# Kostache
2010-05-17 04:55:59 +03:00
2012-11-22 13:27:47 +02:00
Kostache is a [Kohana 3 ](https://github.com/kohana/kohana ) module for using [Mustache ](http://mustache.github.com/ ) templates in your application.
2010-05-17 04:55:59 +03:00
2012-10-24 06:30:33 +03:00
## Usage
2010-05-18 05:42:48 +03:00
2012-10-24 06:30:33 +03:00
To use, simply create a POPO (Plain Old PHP Object) like so:
2010-05-18 05:42:48 +03:00
2012-10-24 06:30:33 +03:00
```php
< ?php
2010-05-18 05:42:48 +03:00
2012-10-24 06:30:33 +03:00
class View_Test
{
public $hello = 'world';
2010-05-18 05:42:48 +03:00
2012-10-24 06:30:33 +03:00
public function testing()
{
return 'foobar';
}
}
```
2010-05-18 05:42:48 +03:00
2012-10-24 06:30:33 +03:00
And create a mustache renderer. The parameter to the engine method is the template name to use.
2010-09-04 18:09:46 +03:00
2012-10-24 06:30:33 +03:00
```php
< ?php
2010-09-04 18:09:46 +03:00
2012-10-24 06:54:19 +03:00
$renderer = Kostache::factory();
2012-10-24 06:30:33 +03:00
```
2010-09-04 18:09:46 +03:00
2012-10-24 06:30:33 +03:00
And render it:
2010-09-04 18:09:46 +03:00
2012-10-24 06:30:33 +03:00
```php
< ?php
2010-08-04 22:14:19 +03:00
2012-10-24 06:30:33 +03:00
$this->response->body($renderer->render(new View_Test));
```
2010-08-04 22:14:19 +03:00
2012-10-24 06:30:33 +03:00
## Templates
2010-08-04 22:14:19 +03:00
2012-10-24 06:30:33 +03:00
Templates should go in the `templates/` directory in your cascading file system. They should have a .mustache extension.
## Partials
2010-09-06 05:48:19 +03:00
2012-10-24 06:30:33 +03:00
Partials are loaded automatically based on the name used in the template. So if you reference `{{>foobar}}` in your template, it will look for that partial in `templates/partials/foobar.mustache` .
2010-09-06 05:48:19 +03:00
2012-11-01 03:39:43 +02:00
# Layouts
KOstache supports layouts. To use, just add a `templates/layout.mustache` file (a simple one is already provided), and use `Kostache_Layout` for your renderer instead of `Kostache` . You'll probably want to put a `$title` property in your view class. The layout should include a `{{>content}}` partial to render the body of the page.
# Additional Information
2010-05-18 03:37:53 +03:00
For specific usage and documentation, see:
2010-05-17 04:55:59 +03:00
[PHP Mustache ](http://github.com/bobthecow/mustache.php )
2012-11-22 13:27:47 +02:00
[Original Mustache ](http://mustache.github.com/ )