aymdev/ekf

Element-Key-Flag: another PHP template engine.

v2.1.0 2018-11-06 21:31 UTC

README

EKF: Element-Key-Flag Just another PHP template engine.

Install

Composer: (recomended) run composer require aymdev/ekf and include vendor/autoload.php.

Git: clone this repository and use src/EKF.php. You will also need to include the exception class files to handle it properly.

Getting Started

Create a new instance with the template path and an array containing the variable to use for it. Then get the parsed template with the Render method:

use Phunder\EKF\EKF;

$file = 'path/to/template.html';
$vars = [
    'variable'  => 'foo',
    'array'     => [
        'bar',
        'baz'
    ]
];

$template = new EKF($file, $vars);

echo $template->Render();

Syntax

Variables

Output variables

<h1>{{ #variable }}</h1>

Apply filters

<div>{{ #html_data |RAW }}</div>

Use arrays keys or objects properties

<h1>{{ #array.key }}</h1>

Loops

Make loops (even nested)

<ul>
    {{ loop #array as #item }}
        <li>{{ item }}</li>
    {{ endloop }}
</ul>

Template inheriting

Build base templates
base.html

{{ insert #list }}

Then inherit a base template
page.html

{{ template "base.html" }}

{{ section #list }}
<ul>
    {{ loop #array as #item }}
        <li>{{ item }}</li>
    {{ endloop }}
</ul>
{{ section #list }}

Importing templates

Include another file in your template and it will be parsed as well, with the importing template variables accessibles too.
template.html

{{ template "base.html" }}

{{ section #list }}
    <h1>Title</h1>
    {{ import "import.html" }}
{{ section #list }}

import.html

{{ #foo }}