Cherry-project Template Engine

v1.1.0 2019-05-11 18:55 UTC

This package is auto-updated.

Last update: 2023-03-12 03:54:49 UTC


The Cherry-project Template wrapper

GitHub license

GitHub release

Packagist Version


Install from composer composer require cherry-project/templater

Include Autoloader in your main file (Ex.: index.php)

require_once __DIR__ . '/vendor/autoload.php';

Class Templater

Import class

use Cherry\Templating\Templater;

Crete class new object

$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:

<!doctype html>
<html lang="en">
    <meta charset="UTF-8">
    <title>Hello, World!</title>
    <h1>Hello, {{ name }}!</h1>

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:

$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:

$response = $templateEngine->render('index.templater.php', [
    'name' => 'Temuri'

After that $response Variable will contain Response object and we can print it:

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