Skip to content

[READ ONLY] Subtree split of `Lucid\Template`

License

Notifications You must be signed in to change notification settings

lucidphp/template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Templating library

Author Source Code Software License

Build Status Code Coverage HHVM

An extendable templating library for php.

Requirements

php >= 5.6

Installation

$ composer require lucid/template

Getting started

<?php

use Lucid\Template\Engine;
use Lucid\Template\Loader\FilesystemLoader;

$engine = new Engine(new Loader(['path/to/templates']));

$engine->render('partials/content.php', ['title' => 'Hello World!']);

Partials

Inserts

<html>
    <body>

    <div id="container">
        $view->insert('partials/footer.php');
        $view->insert('partials/content.php');
        $view->insert('partials/footer.php');
    </div>

    </body>
</html>

Extending existing templates

The templates

partials/content.php:

<?= $view->extend('master.php') ?>
<?= $view->section('content') ?>
    <p>Extended content</p>
<?= $view->endsection() ?>

master.php:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8"/>
    <title><?= $title ?></title>
  </head>
  <body>
    <div id="main">
      <?= $view->section('content') ?>
        <p>The default content.</p>
      <?= $view->endsection() ?>
    </div>
  </body>
</html>

Sections

Tempalte Listeners

Adding template listeners can be usefull if you want to add data to a specific template. This data my be derieved from any resource you may want (e.g. DB, Container, etc).

<?php

$view->addListener('head.php', new RenderHeadListener($headerData));

Your listener may look something like this

<?php

use Lucid\Template\Listener\ListenerInterface;

class RenderHeadListener implements ListenerInterface
{
	private $data;

	public function __construct(array $headerData)
	{
		$this->data = $data;
	}

    public function onRender(TemplateDataInterface $data)
	{
		// add header data to `$data`
	}
}

About

[READ ONLY] Subtree split of `Lucid\Template`

Resources

License

Stars

Watchers

Forks

Packages

No packages published