fenom/docs/usage.md

39 lines
841 B
Markdown
Raw Normal View History

2013-06-28 11:53:53 +04:00
Basic usage
===========
### Initialize Fenom
2013-06-28 11:53:53 +04:00
2014-02-07 23:44:03 +04:00
Creating an object via factory method
2013-06-28 11:53:53 +04:00
```php
$fenom = Fenom::factory('/path/to/templates', '/path/to/compiled/template', $options);
```
2013-06-28 11:53:53 +04:00
2014-02-07 23:44:03 +04:00
Creating an object via `new` operator
```php
$fenom = new Fenom(new Provider('/path/to/templates'));
2013-06-28 11:53:53 +04:00
$fenom->setCompileDir('/path/to/template/cache');
$fenom->setOptions($options);
```
2014-02-07 23:44:03 +04:00
### Rendering template
2013-06-28 11:53:53 +04:00
Output template
2013-06-28 11:53:53 +04:00
```php
$fenom->display("template/name.tpl", $vars);
```
2014-02-07 23:44:03 +04:00
Get the result of rendering the template
```php
$result = $fenom->fetch("template/name.tpl", $vars);
```
2014-02-07 23:44:03 +04:00
Create the pipeline of rendering into callback
```php
2013-07-04 09:57:07 +04:00
$fenom->pipe(
"template/sitemap.tpl",
$vars,
$callback = [new SplFileObject("/tmp/sitemap.xml", "w"), "fwrite"], // pipe to file /tmp/sitemap.xml
$chunk_size = 1e6 // chunk size for callback
);
2013-07-04 09:57:07 +04:00
```