kostache/README.markdown

58 lines
1.4 KiB
Markdown
Raw Normal View History

# Kostache
2010-05-17 04:55:59 +03: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
2012-10-24 06:30:33 +03:00
To use, simply create a POPO (Plain Old PHP Object) like so:
2012-10-24 06:30:33 +03:00
```php
<?php
2012-10-24 06:30:33 +03:00
class View_Test
{
public $hello = 'world';
2012-10-24 06:30:33 +03:00
public function testing()
{
return 'foobar';
}
}
```
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.
2012-10-24 06:30:33 +03:00
```php
<?php
2012-10-24 06:54:19 +03:00
$renderer = Kostache::factory();
2012-10-24 06:30:33 +03:00
```
2012-10-24 06:30:33 +03:00
And render it:
2012-10-24 06:30:33 +03:00
```php
<?php
2012-10-24 06:30:33 +03:00
$this->response->body($renderer->render(new View_Test));
```
2012-10-24 06:30:33 +03:00
## Templates
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
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`.
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)
[Original Mustache](http://mustache.github.com/)