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

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

baagee/php-template
===================

PHP Template library

v0.0.4(5y ago)1541MITPHPPHP &gt;=7.1

Since Mar 25Pushed 5y agoCompare

[ Source](https://github.com/baagee/php-template)[ Packagist](https://packagist.org/packages/baagee/php-template)[ RSS](/packages/baagee-php-template/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (3)DependenciesVersions (5)Used By (1)

Template php轻量的模板解析引擎
=====================

[](#template-php轻量的模板解析引擎)

php Template View

内置主要方法

```
interface ViewInterface
{
    // 渲染，返回解析后的html模板
    public static function render(string $source, array $data = []);

    // 渲染并输出 没有返回
    public static function display(string $source, array $data = []);
}
```

基本使用
----

[](#基本使用)

### 输出一个变量

[](#输出一个变量)

输出标签是由一对花括号做为定界符的，不支持输出数组

```
跑车简介：{{$item['aaa']['description']}}
```

### if分支判断

[](#if分支判断)

```
{{if $pp['active']}}
{{$p}}
{{else}}
{{$p}}
{{/if}}或者是{{fi}}
```

#### if elseif

[](#if-elseif)

```
{{if $pp['active']==1}}
{{$p}}
{{elseif $pp['active']==2}}
{{$p}}
{{else}}
{{$p}}
{{fi}}
```

### 循环语句

[](#循环语句)

循环一个数组用 loop 标签，与php中的 foreach 函数类似，第一个参数为数组的索引，第二个参数为数组第一项的值 只要标签成对匹配，模板中的标签是可以嵌套使用的。

```
{{loop $list $k $item}}

                车牌号
                跑车名
                发布日期

                {{$item['ccc']}}
                {{$item['sss']['name']}}
                {{$item['date']}}

        车牌名：{{$item['eee']}}
        跑车简介：{{$item['rere']['description']}}

{{/loop}}或者{{pool}}
```

### 一行php语句

[](#一行php语句)

由于某些时候需要使用一些php来输出内容，比如格式化时间戳为日期时，此写法并不支持多行php语句

```

```

### 引用一个模板文件

[](#引用一个模板文件)

在模板中如果需要引用其它模板文件可以使用以下的方法，路径从View下级开始写，被引入的模板里也可以引入其他模板，多层次嵌套

```
{{include '/common/header.tpl'}}

....

{{include 'common/footer.tpl'}}
```

### layout布局

[](#layout布局)

可以多层次嵌套布局，比如article控制器的模板，使用叫做main1的布局，而main1又使用了main2的布局...

#### 父模板挖坑 baseLayout.tpl

[](#父模板挖坑-baselayouttpl)

```
>

    {{$page_title}}

    {{hole header}}

{{hole content}}

```

#### 子模板继承父模板填坑。mainLayout.tpl

[](#子模板继承父模板填坑mainlayouttpl)

```

{{layout '/common/baseLayout.tpl'}}

{{fill header}}

    {{hole header-js}}
    {{hole header-css}}
{{end header}}

{{fill content}}

    {{include 'common/top.tpl'}}
    {{include 'common/sidebar.tpl'}}

                        {{$page_title}}

                    {{$page_description}}

        {{hole content}}

    {{hole javascript}}
{{end content}}
```

#### 孙模板 具体的action对应的模板

[](#孙模板--具体的action对应的模板)

```

{{layout 'common/mainLayout.tpl'}}

{{fill header-js}}

{{end header-js}}

{{fill header-css}}

{{end header-css}}

{{fill content}}

            hello

{{end content}}

abc

{{fill javascript}}

        alert(111);

{{end javascript}}
```

#### 注意

[](#注意)

1. 并不是每个父模板挖的坑子模板都必须填，可以根据需求填。
2. 子模板不能跨级填坑，只能填它父亲的坑，不能填爷爷的坑。
3. 坑和坑之间的字符不会输出，模板编译时会直接丢弃填坑标签之外的字符。

### 具体示例代码：tests目录

[](#具体示例代码tests目录)

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 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 ~156 days

Total

4

Last Release

2139d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/22995500?v=4)[BaAGee](/maintainers/baagee)[@baagee](https://github.com/baagee)

---

Top Contributors

[![baagee](https://avatars.githubusercontent.com/u/22995500?v=4)](https://github.com/baagee "baagee (1 commits)")

---

Tags

phptemplateview

### Embed Badge

![Health badge](/badges/baagee-php-template/health.svg)

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

###  Alternatives

[eftec/bladeone

The standalone version Blade Template Engine from Laravel in a single php file

8208.4M87](/packages/eftec-bladeone)[eftec/bladeonehtml

The standalone version Blade Template Engine from Laravel in a single php file

1018.1k5](/packages/eftec-bladeonehtml)

PHPackages © 2026

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