Rumah  >  Artikel  >  pembangunan bahagian belakang  >  原生 PHP 模板系统:Plates

原生 PHP 模板系统:Plates

WBOY
WBOYasal
2016-06-20 12:56:562789semak imbas

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

<?php $this->layout('template', ['title' => 'User Profile']) ?><h1>User Profile</h1><p>Hello, <?=$this->e($name)?></p>

The layout template

template.php

<html><head>    <title><?=$this->e($title)?></title></head><body><?=$this->section('content')?></body></html>


值得关注的特性

  • 原生 PHP 模板,不需要学习新的语法

  • Plates 是模板系统,不是模板语言

  • Plates 鼓励使用现有的 PHP 函数

  • 使用模板布局和继承提升代码复用性

  • 跨模板数据共享

  • 内置转义帮助函数

  • 无固定框架,可以运用在任意的项目中

  • 解耦设计,容易测试

  • 支持 Composer,兼容 PSR-2

项目主页:http://www.open-open.com/lib/view/home/1431008255398

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn