Makes data optional
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
# Changelog
|
||||
|
||||
## v0.3.0
|
||||
|
||||
Released 2019-10-27
|
||||
|
||||
- Makes data passed to view optional
|
||||
|
||||
## v0.2.0
|
||||
|
||||
Released 2019-10-19
|
||||
|
||||
@@ -3,27 +3,12 @@ Simple templating system
|
||||
|
||||
# Usage
|
||||
|
||||
1. Add repository (github) to your composer.json.
|
||||
```json
|
||||
{
|
||||
"repositories": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/kavalanche/template.git"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"kavalanche/template": "0.2.0"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
2. Require kavalanche/template
|
||||
1. Require kavalanche/template (composer)
|
||||
```bash
|
||||
composer require kavalanche/template
|
||||
```
|
||||
|
||||
3. Create instance of `Kavalanche\Template\View` somewhere in your front controller or other bootstrapping part of the code.
|
||||
2. Create instance of `Kavalanche\Template\View` somewhere in your front controller or other bootstrapping part of the code.
|
||||
```php
|
||||
// without default base view defined
|
||||
$view = new Kavalanche\Template\View('/path/to/templates');
|
||||
@@ -31,9 +16,9 @@ $view = new Kavalanche\Template\View('/path/to/templates');
|
||||
$view = new Kavalanche\Template\View('/path/to/templates', 'base');
|
||||
```
|
||||
|
||||
4. Pass `$view` to your controller or wherever you want.
|
||||
3. Pass `$view` to your controller or wherever you want.
|
||||
|
||||
5. Invoke `render` method and pass variables to view file.
|
||||
4. Invoke `render` method and pass variables to view file.
|
||||
```php
|
||||
public function index() {
|
||||
$list = [...];
|
||||
@@ -42,14 +27,14 @@ public function index() {
|
||||
}
|
||||
```
|
||||
|
||||
6. Use your data inside view file.
|
||||
5. Use your data inside view file.
|
||||
```php
|
||||
foreach ($list as $item) {
|
||||
// whatever
|
||||
}
|
||||
```
|
||||
|
||||
7. Remember that if you define base view, it must contain this or similar line od code:
|
||||
6. Remember that if you define base view, it must contain this or similar line od code:
|
||||
```php
|
||||
echo $content;
|
||||
```
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ class View {
|
||||
}
|
||||
}
|
||||
|
||||
public function render($view, array $data, $base = null) {
|
||||
public function render($view, array $data = [], $base = null) {
|
||||
extract($data);
|
||||
|
||||
if (!file_exists($this->templateDirectory . '/' . $view . '.php')) {
|
||||
|
||||
Reference in New Issue
Block a user