Here is a simple example of how to use Plates. We will assume the following directory stucture:
`-- path `-- to `-- templates |-- template.php |-- profile.php
Within your controller
// Create new Plates instance$templates = new League\Plates\Engine('/path/to/templates');// Render a templateecho $templates->render('profile', ['name' => 'Jonathan']); The page template
profile.php
layout('template', ['title' => 'User Profile']) ?>User Profile
Hello, =$this->e($name)?>
The layout template
template.php
=$this->e($title)?> =$this->section('content')?>
值得关注的特性
-
原生 PHP 模板,不需要学习新的语法
-
Plates 是模板系统,不是模板语言
-
Plates 鼓励使用现有的 PHP 函数
-
使用模板布局和继承提升代码复用性
-
跨模板数据共享
-
内置转义帮助函数
-
无固定框架,可以运用在任意的项目中
-
解耦设计,容易测试
-
支持 Composer,兼容 PSR-2
项目主页:http://www.open-open.com/lib/view/home/1431008255398