plates 是原生 php 模板系统,非常容易使用和扩展,灵感来源于 twig 模板引擎,包括现代化的模板语言功能。plates 主要是为在编译模板语言中选择使用原生 php 模板的开发者提供的。
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 profilehello, e($name)?>
the layout template template.php
e($title)?>section('content')?>
值得关注的特性 原生 php 模板,不需要学习新的语法
plates 是模板系统,不是模板语言
plates 鼓励使用现有的 php 函数
使用模板布局和继承提升代码复用性
跨模板数据共享
内置转义帮助函数
无固定框架,可以运用在任意的项目中
解耦设计,容易测试
支持 composer,兼容 psr-2
项目主页:http://www.open-open.com/lib/view/home/1431008255398