当前位置: 首页 > 工具软件 > Plates > 使用案例 >

php 系统模版_原生 PHP 模板系统:Plates

蒲昀
2023-12-01

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

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

 类似资料: