| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
ygw3
9年前发布

原生 PHP 模板系统:Plates

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 template  echo $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

 本文由用户 ygw3 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1431008255398.html
Plates 模板引擎