-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ABGEO07/develop
Develop
- Loading branch information
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Cherry-templater Changelog | ||
|
||
## [v1.0.0](https://github.com/ABGEO07/cherry-templater/releases/tag/v1.0.0 "v1.0.0") (2019-03-29) | ||
#### The first stable version | ||
|
||
- Package available on: `composer require cherry-project/templater` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,79 @@ | ||
# Cherry-Templater | ||
The Cherry-project Template wrapper | ||
|
||
[![GitHub license](https://img.shields.io/github/license/abgeo07/cherry-templater.svg)](https://github.com/ABGEO07/cherry-templater/blob/master/LICENSE) | ||
|
||
[![GitHub release](https://img.shields.io/github/release/abgeo07/cherry-templater.svg)](https://github.com/ABGEO07/cherry-templater/releases) | ||
|
||
[![Packagist Version](https://img.shields.io/packagist/v/cherry-project/templater.svg "Packagist Version")](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 | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Hello, World!</title> | ||
</head> | ||
<body> | ||
<h1>Hello, <?php echo $name; ?>!</h1> | ||
</body> | ||
</html> | ||
``` | ||
|
||
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** |