Heim  >  Artikel  >  Backend-Entwicklung  >  原生 PHP 模板系统:Plates

原生 PHP 模板系统:Plates

WBOY
WBOYOriginal
2016-06-20 12:56:562787Durchsuche

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

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn