Skip to content

Commit 323b4f0

Browse files
authored
Merge pull request #1 from ABGEO07/develop
Develop
2 parents 607e826 + f12226f commit 323b4f0

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Cherry-templater Changelog
2+
3+
## [v1.0.0](https://github.com/ABGEO07/cherry-templater/releases/tag/v1.0.0 "v1.0.0") (2019-03-29)
4+
#### The first stable version
5+
6+
- Package available on: `composer require cherry-project/templater`

README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,79 @@
11
# Cherry-Templater
2+
The Cherry-project Template wrapper
3+
4+
[![GitHub license](https://img.shields.io/github/license/abgeo07/cherry-templater.svg)](https://github.com/ABGEO07/cherry-templater/blob/master/LICENSE)
5+
6+
[![GitHub release](https://img.shields.io/github/release/abgeo07/cherry-templater.svg)](https://github.com/ABGEO07/cherry-templater/releases)
7+
8+
[![Packagist Version](https://img.shields.io/packagist/v/cherry-project/templater.svg "Packagist Version")](https://packagist.org/packages/cherry-project/templater "Packagist Version")
9+
10+
------------
11+
12+
## Including
13+
**Install from composer** `composer require cherry-project/templater`
14+
15+
**Include Autoloader in your main file** (Ex.: index.php)
16+
```php
17+
require_once __DIR__ . '/vendor/autoload.php';
18+
```
19+
20+
## Class Templater
21+
Import class
22+
```php
23+
use Cherry\Templating\Templater;
24+
```
25+
Crete class new object
26+
```php
27+
$templateEngine = new Templater(PATH_TO_TEMPLATES);
28+
```
29+
30+
Where `PATH_TO_TEMPLATES` is path to your templates folder. Ex.: `__DIR__ . '/../examples/templates'`
31+
32+
Create new template in you'r templates folder (Ex.: `index.templater.php`) which contains simple HTML
33+
Markup with PHP:
34+
35+
```html
36+
<!doctype html>
37+
<html lang="en">
38+
<head>
39+
<meta charset="UTF-8">
40+
<title>Hello, World!</title>
41+
</head>
42+
<body>
43+
<h1>Hello, <?php echo $name; ?>!</h1>
44+
</body>
45+
</html>
46+
```
47+
48+
Then you can call `$templateEngine` objects `render` method with two arguments:
49+
50+
- Name of rendering template
51+
- Arguments (PHP Variables) for template
52+
53+
Arguments is simple PHP Array:
54+
55+
```php
56+
$args = [
57+
'name' => 'Name 1',
58+
'surname' => 'Surname 1'
59+
];
60+
```
61+
62+
Our `index.templater.php` template contains only one PHP Variable `$name`, so we must pass it in `render` method:
63+
64+
```php
65+
$response = $templateEngine->render('index.templater.php', [
66+
'name' => 'Temuri'
67+
]);
68+
```
69+
70+
After that `$response` Variable will contain Response object and we can print it:
71+
72+
```php
73+
echo $response;
74+
```
75+
76+
In first argument of `render` method we can put full filename of template (`index.templater.php`)
77+
or only template name (name without file extension Ex.: `index`)
278

379
**2019 &copy; Cherry-project**

0 commit comments

Comments
 (0)