Olov is a micro templating engine for PHP
Olov uses native PHP templates but with a single elegant function o()
to help you do amazing things with very simple syntax., (*1)
1. Defining blocks...
Blocks are defined like this: <?php o('+blockname') ?> with a matching close
like this <?php o('-blockname') ?>., (*2)
Example of block definitions:, (*3)
<!DOCTYPE html>
<html>
<head><title>Welcome to Olov!</title></head>
<body>
The default content goes here and can be replaced in a child template that
extends this one.
, (*4)
</body>
</html>
2. Extending a base template...
To extend another template, at the very top, do: <?php o('::base.html.php') ?>
See example of block definitions below., (*5)
Pimp My Header
To override the default +content block, create one in the child template
and put whatever youu like in the new block!
, (*6)
<small>© 2020 <i>Hmm, upgrades.</i></small>
3. Template partials...
To include a template partial, do: <?php o(':partial.html.php') ?>
See example of partial include below (note the difference between the syntax for ::exending and :including), (*7)
Content body here., (*8)
4. Template variables...
You can define your template variables in an associative array[] like this:, (*9)
[
'title' => 'Olov Template Engine for PHP',
'body' => 'Values are automatically escaped when used the template.',
'tags' => [
'php', 'template engine', 'olov'
]
];
```
**Then create Olov engine instance and render:**
```php
// Our templates folder...
$templates_path = "./my/templates/folder/":
// New instance of Olov
$o = Olov::o($templates_path);
// Render...
$o->render('hello.html.php', $vars);
?>
Our template: ./hello.html.php, (*10)
= o('page.title') ?>
= o('page.body') ?>
, (*11)
Character count: = o('page.body|length') ?>, (*12)
<small>© 2020 <i>Hmm, upgrades.</i></small>
5. Loops
You can automatically print array values by doing:, (*13)
<ul>
<?php o('page.tags|each'); ?>
</ul>
This will output:, (*14)
Olov wraps your array values with the <li> by default and auto escapes the text values.
Olov can also wrap your loop items in multiple concentric layers of tags. For eaxample:, (*15)
<?php o('page.tags|each:b,a,li'); ?>
Outputs:, (*16)
<li><a><b>Text Value</b></a></li>
To set tag properties and attributes, define your list in your $vars array like this:, (*17)
$vars = [
// ....
'users' => [
['Jamie Foxx', 'a:href'=>'https://en.wikipedia.org/wiki/Jamie_Foxx', 'li:class'=>'name'],
['Marlon Brando', 'a:href'=>'https://en.wikipedia.org/wiki/Marlon_Brando', 'li:class'=>'name'],
['Thandie Newton', 'a:href'=>'https://en.wikipedia.org/wiki/Thandie_Newton', 'li:class'=>'name']
]
];
Then..., (*18)
<ul class="hollywood-actors">
<?php o('page.users|each:a,li'); ?>
</ul>
Throw in the blender and ..., (*19)
<ul class="hollywood-actors">
<li class="name"><a href="https://en.wikipedia.org/wiki/Jamie_Foxx">Jamie Foxx</a></li>
<li class="name"><a href="https://en.wikipedia.org/wiki/Marlon_Brando">Marlon Brando</a></li>
<li class="name"><a href="https://en.wikipedia.org/wiki/Thandie_Newton">Thandie Newton</a></li>
</ul>
6. Installation
You can require with Composer:, (*20)
$ composer require "olov/olov:~1.0"
Or clone this repo with:, (*21)
$ git clone https://github.com/olovphp/Olov.git
Or download the zip folder., (*22)
This is a quickstart guide not a real documentation (that is on the way.) In the meantime
please clone the repo and run examples/index.php to see a live example. I hope you
find this useful in your projects and bug reports are most welcome!, (*23)