PHPackages                             ryx16/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. ryx16/template

ActiveLibrary

ryx16/template
==============

An efficient swoole framework

02PHP

Since Jun 23Pushed 1y agoCompare

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

READMEChangelogDependenciesVersions (2)Used By (0)

Template
========

[](#template)

"easyswoole/spl": "^2.0",

安装
==

[](#安装)

composer require ryx16/template @dev -W --ignore-platform-reqs

实现原理
----

[](#实现原理)

注册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作为渲染器)

```
