PHPackages                             easyswoole/template - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. easyswoole/template

ActiveLibrary[Framework](/categories/framework)

easyswoole/template
===================

An efficient swoole framework

1.2.1(3mo ago)421.0k—5.4%74Apache-2.0PHP

Since May 23Pushed 3mo agoCompare

[ Source](https://github.com/easy-swoole/template)[ Packagist](https://packagist.org/packages/easyswoole/template)[ Docs](https://www.easyswoole.com/)[ RSS](/packages/easyswoole-template/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (13)Used By (4)

Template
========

[](#template)

实现原理
----

[](#实现原理)

注册N个自定义进程做渲染进程，进程内关闭协程环境，并监听UNIXSOCK，客户端调用携程的client客户端发送数据给进程渲染，进程再返回结果给客户端，用来解决PHP模板引擎协程安全问题。可以实现渲染接口，根据自己的喜好引入smarty或者是blade或者是其他引擎.

引入模板引擎类
-------

[](#引入模板引擎类)

下面列举一些常用的模板引擎包方便引入使用:

### [smarty/smarty](https://github.com/smarty-php/smarty)

[](#smartysmarty)

Smarty是一个使用PHP写出来的模板引擎,是目前业界最著名的PHP模板引擎之一

> composer require smarty/smarty=~3.1

### [league/plates](https://github.com/thephpleague/plates)

[](#leagueplates)

使用原生PHP语法的非编译型模板引擎，更低的学习成本和更高的自由度

> composer require league/plates=3.\*

### [duncan3dc/blade](https://github.com/duncan3dc/blade)

[](#duncan3dcblade)

Laravel框架使用的模板引擎

> composer require duncan3dc/blade=^4.5

### [topthink/think-template](https://github.com/top-think/think-template)

[](#topthinkthink-template)

ThinkPHP框架使用的模板引擎

> composer require topthink/think-template

渲染模板
----

[](#渲染模板)

选择一个心仪的模板引擎，并实现RenderInterface接口，当进程收到一条渲染指令时，会调用该实现类的render方法进行渲染，渲染结束后调用afterRender方法，可在此处进行变量释放清理等操作，以Smarty引擎为例，创建一个渲染器， 并渲染的最小例子如下

### 用Smarty作为渲染器

[](#用smarty作为渲染器)

```
