PHPackages                             epii/template-engine - 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. [Templating &amp; Views](/categories/templating)
4. /
5. epii/template-engine

ActiveLibrary[Templating &amp; Views](/categories/templating)

epii/template-engine
====================

一个超级简单的php template engine，可扩展其它模板引擎。

1.1.7(5y ago)24643MITPHPPHP &gt;=5.6

Since Dec 25Pushed 4y ago1 watchersCompare

[ Source](https://github.com/epaii/epii-php-template)[ Packagist](https://packagist.org/packages/epii/template-engine)[ RSS](/packages/epii-template-engine/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (10)DependenciesVersions (25)Used By (3)

install

```
{
    "require": {
        "epii/template-engine": ">=0.0.1"
    }
}
```

```
require_once __DIR__ . "/vendor/autoload.php";

$config = ["tpl_dir" => __DIR__."/view","cache_dir"=>__DIR__."/cache"];

\epii\template\View::setEngine($config);

$data = ["name" => "张三", "age" => "222","key_name"=>"name1","info"=>["name1"=>"李四"],
    "list"=>[
        ["name"=>"任0"],
        ["name"=>"任1"],
        ["name"=>"任2"],
        ["name"=>"任3"]
    ]
];
\epii\template\View::display("a/index", $data);
```

其它方法

```
View::fetch($file, $data);
View::display($file, $data);
View::fetchContent($content, $data);
View::displayContent($content, $data);

View::addCommonData(Array $data);//设置公共数据

//自定义规则
View::addStringRule($string_find, $string_replace);
View::addPregRule($preg_find, $replace_string);
View::addPregRuleCallBack($preg_find, callable $replace);
```

支持第三方引擎

```
View::setEngine($config,支持自定义模板引擎类,默认为\epii\template\engine\EpiiViewEngine::class);
// 如果使用纯php本身语言为模板，只需使用\epii\template\engine\PhpViewEngine::class  即可
//第三方类只需实现 接口 epii\template\i\IEpiiViewEngine

```

在模板文件中 a/index.php

> 以下语法为默认模板引擎\\epii\\template\\engine\\EpiiViewEngine::class

```
{$name} ,{$info.name1},{$info.$key_name}//方法一
, //方法二
 ////方法三

```

函数支持

```
{$time_int|date,Y-m-d H:i:s,$0} //$0 代表当前值，逗号隔开为参数顺序

```

也可以

```
{:date,Y-m-d H:i:s,$time_int} //

```

函数中的参数如果有","号，用"\\,"代替

如

```
{:rtrim,aaa\,,\,}// 相当于 echo rtrim("aaa,",",");

```

函数中的参数如果有变量，可以直接写变量，但如果使用变量连接则用"\\{\\}"来区分变量

如

```
{:rtrim,aaa\,,$a} // 相当于 echo rtrim("aaa,",$a);
{:rtrim,aaa\,,aa\{$a\}bb} // 相当于 echo rtrim("aaa,","aa".$a."bb");

```

遍历与其他

```
{loop $list}

    {$key},{$value.name}

{/loop}

{loop $list $mykey=>$myvalue}
{$mykey},{$myvalue}
{/loop}

{foreach $list}

    {$key},{$value.name}

{/foreach}

{foreach $list $mykey=>$myvalue}
{$mykey},{$myvalue}
{/foreach}

{if  $name=="aaa" }
    1111111111
{elseif $name=="cccc"}
    333333
{else}
   00000000
{/if}

```

包含其它模板文件

```
{include a/b}
{include a/b\{$a\}}
{include "a/b\{$a\}"}

```

?号语法

```
{? $a}
{? $a 1}
{? $a b}

```

相当于

```
 //
 //

```

并且

```
{$name?}
{$name?"张三"}
{$info["age"]?"18岁"}
{$info.age?"18岁"}
{loop $list.info?[]}

```

相当于

```
 //
 //
 //
 //

```

默认参数

```
{$_view.get.}
{$_view.post.}
{$_view.server.}
{$_view.cookie.}
{$_view.sesstion.}

```

> 支持php原生所有语法

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~22 days

Recently: every ~59 days

Total

24

Last Release

2189d ago

Major Versions

0.0.9 → 1.0.02019-01-09

### Community

Maintainers

![](https://www.gravatar.com/avatar/6fe8c6a6a5b64efc9fcda02b7fe3b660d0da22ea26ea627cbba9e5466779198c?d=identicon)[epii](/maintainers/epii)

---

Top Contributors

[![epaii](https://avatars.githubusercontent.com/u/15167976?v=4)](https://github.com/epaii "epaii (57 commits)")

### Embed Badge

![Health badge](/badges/epii-template-engine/health.svg)

```
[![Health](https://phpackages.com/badges/epii-template-engine/health.svg)](https://phpackages.com/packages/epii-template-engine)
```

###  Alternatives

[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[whitecube/nova-flexible-content

Flexible Content &amp; Repeater Fields for Laravel Nova.

8053.0M25](/packages/whitecube-nova-flexible-content)[mopa/bootstrap-bundle

Easy integration of twitters bootstrap into symfony2

7042.9M33](/packages/mopa-bootstrap-bundle)[limenius/react-bundle

Client and Server-side react rendering in a Symfony Bundle

3871.2M](/packages/limenius-react-bundle)[nicmart/string-template

StringTemplate is a very simple string template engine for php. I've written it to have a thing like sprintf, but with named and nested substutions.

2101.7M30](/packages/nicmart-string-template)[symfony/ux-icons

Renders local and remote SVG icons in your Twig templates.

555.8M69](/packages/symfony-ux-icons)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
