https://github.com/cherry-framework/templater
The Cherry-project Template wrapper
https://github.com/cherry-framework/templater
cherry composer templater
Last synced: 3 months ago
JSON representation
The Cherry-project Template wrapper
- Host: GitHub
- URL: https://github.com/cherry-framework/templater
- Owner: cherry-framework
- License: mit
- Created: 2019-03-28T20:48:44.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-05-11T19:01:37.000Z (about 7 years ago)
- Last Synced: 2025-09-05T16:55:07.625Z (10 months ago)
- Topics: cherry, composer, templater
- Language: PHP
- Homepage:
- Size: 14.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Cherry-Templater
The Cherry-project Template wrapper
[](https://github.com/ABGEO07/cherry-templater/blob/master/LICENSE)
[](https://github.com/ABGEO07/cherry-templater/releases)
[](https://packagist.org/packages/cherry-project/templater "Packagist Version")
------------
## Including
**Install from composer** `composer require cherry-project/templater`
**Include Autoloader in your main file** (Ex.: index.php)
```php
require_once __DIR__ . '/vendor/autoload.php';
```
## Class Templater
Import class
```php
use Cherry\Templating\Templater;
```
Crete class new object
```php
$templateEngine = new Templater(PATH_TO_TEMPLATES);
```
Where `PATH_TO_TEMPLATES` is path to your templates folder. Ex.: `__DIR__ . '/../examples/templates'`
Create new template in you'r templates folder (Ex.: `index.templater.php`) which contains simple HTML
Markup with PHP:
```html
Hello, World!
Hello, {{ name }}!
```
Then you can call `$templateEngine` objects `render` method with two arguments:
- Name of rendering template
- Arguments (PHP Variables) for template
Arguments is simple PHP Array:
```php
$args = [
'name' => 'Name 1',
'surname' => 'Surname 1'
];
```
Our `index.templater.php` template contains only one PHP Variable `$name`, so we must pass it in `render` method:
```php
$response = $templateEngine->render('index.templater.php', [
'name' => 'Temuri'
]);
```
After that `$response` Variable will contain Response object and we can print it:
```php
echo $response;
```
In first argument of `render` method we can put full filename of template (`index.templater.php`)
or only template name (name without file extension Ex.: `index`)
**2019 © Cherry-project**