lucid/template
Composer 安装命令:
composer require lucid/template
包简介
Templating library
关键字:
README 文档
README
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` } }
统计信息
- 总下载量: 27
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-12-15