PHPackages                             phppkg/easytpl - 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. phppkg/easytpl

ActiveTemplate

phppkg/easytpl
==============

⚡️ Simple and fastly template engine for PHP

v1.2.2(2y ago)25613↓100%2[2 issues](https://github.com/phppkg/easytpl/issues)MITPHPPHP &gt;=8.0.1CI passing

Since Nov 11Pushed 3mo ago2 watchersCompare

[ Source](https://github.com/phppkg/easytpl)[ Packagist](https://packagist.org/packages/phppkg/easytpl)[ Docs](https://github.com/phppkg/easytpl)[ RSS](/packages/phppkg-easytpl/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (2)Versions (12)Used By (0)

EasyTpl
=======

[](#easytpl)

[![License](https://camo.githubusercontent.com/479c319fb486adfb61f7778001e554a092b510d976d1a78668e8f83894d7448c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f706870706b672f6561737974706c2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Php Version](https://camo.githubusercontent.com/c4315311121a25fb5c47f29610432777bb442736ecbb327bc652a88f93c1d009/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f706870706b672f6561737974706c3f6d61784167653d32353932303030)](https://packagist.org/packages/phppkg/easytpl)[![GitHub tag (latest SemVer)](https://camo.githubusercontent.com/6405d5646368490ac785e3c11d2b6a012738d2debf3c2030d377bdbae8558e83/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7461672f706870706b672f6561737974706c)](https://github.com/phppkg/easytpl)[![Actions Status](https://github.com/phppkg/easytpl/workflows/Unit-Tests/badge.svg)](https://github.com/phppkg/easytpl/actions)[![zh-CN readme](https://camo.githubusercontent.com/aa09c729fc2ea6a01bd2ce90fcc0f6db764ca475c2c16e138c86d4ec4808521f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2545342542382541442545362539362538372d526561646d652d627269676874677265656e2e7376673f7374796c653d666f722d7468652d6261646765266d61784167653d32353932303030)](README.zh-CN.md)

⚡️ Simple and fastly template engine for PHP.

Features
--------

[](#features)

- It's simple, lightweight and fastly.
    - No learning costs, syntax like PHP template
    - It is simply processed and converted into native PHP syntax
    - Compatible with PHP native syntax
- support simple echo print syntax. eg: `{{ var }}` `{{= $var }}` `{{ $var }}` `{{ echo $var }}`
    - allow ignore prefix `$`, will auto append on compile.
- support chained access array value. eg: `{{ $arr.0 }}` `{{ $map.name }}` `{{ $map.user.name }}`
- support all control syntax. such as `if,elseif,else;foreach;for;switch`
- support php builtin function as filters. eg: `{{ $var | ucfirst }}` `{{ date('Y-m-d') }}`
- More secure, the output will be processed automatically through `htmlspecialchars` by default
    - You can set to disable output filtering or manually use the `raw` filter
- support add custom filters.
    - default builtin filters: `upper` `lower` `nl`
- support add custom directive.
    - `EasyTemplate` built in support `layout` `include` `contents`
    - `ExtendTemplate` built in support `extends` `block` `endblock`
- support comments in templates. eg: `{{# comments ... #}}`

Install
-------

[](#install)

**composer**

```
composer require phppkg/easytpl
```

Quick start
-----------

[](#quick-start)

```
use PhpPkg\EasyTpl\EasyTemplate;

$tplCode =  'inhere',
    'tags' => ['php', 'go', 'java'],
]);

echo $str;
```

**Output**:

```
My name is INHERE,
My develop tags:

- php
- go
- java

```

More usage
----------

[](#more-usage)

The syntax is the same as the PHP native template, and the special syntax added is just to make it more convenient to use.

- `EasyTemplate` enables output filtering by default, which can be used to render view templates.
- `TextTemplate` turns off output filtering and is mainly used for text processing, code generation, etc.

### Config template

[](#config-template)

```
use PhpPkg\EasyTpl\EasyTemplate;

$t = EasyTemplate::new([
    'tplDir'   => 'path/to/templates',
    'allowExt' => ['.php', '.tpl'],
]);

// do something ...
```

more settings：

```
/** @var PhpPkg\EasyTpl\EasyTemplate $t */
$t->disableEchoFilter();
$t->addFilter($name, $filterFn);
$t->addFilters([]);
$t->addDirective($name, $handler);
```

### Echo variable

[](#echo-variable)

The following statements are the same, can be used to print out variable values

```
{{ name }}
{{ $name }}
{{= $name }}
{{ echo $name }}
```

More:

```
{{ $name ?: 'inhere' }}
{{ $age > 20 ? '20+' : 'include' . $body;
    }
);
```

---

### Use layout

[](#use-layout)

- page template `home01.tpl`

```
{{ layout('layouts/layout01.tpl') }}

on home: block body;
```

### Use include

[](#use-include)

**Use in template**

```
{{ include('part/header.tpl', ['title' => 'My world']) }}
```

---

Extends template
----------------

[](#extends-template)

New directives:

- `extends` extends a layout template file.
    - syntax: `{{ extends('layouts/main.tpl') }}`
- `block` define a new template block start.
    - syntax: `{{ block 'header' }}`
- `endblock` mark a block end.
    - syntax: `{{ endblock }}`

```
use PhpPkg\EasyTpl\ExtendTemplate;

$et = new ExtendTemplate();
$et->display('home/index.tpl');
```

### Examples for extend

[](#examples-for-extend)

- on layout file: `layouts/main.tpl`

```
{{ block 'header' }}
header contents in layout main.
{{ endblock }}

{{ block 'body' }}
body contents in layout main.
{{ endblock }}

{{ block 'footer' }}
footer contents in layout main.
{{ endblock }}
```

- on page file: `home/index.tpl`

```
{{ extends('layouts/main.tpl') }}

{{ block 'body' }}
body contents in home index.
{{ endblock }}
```

**Rendered results**

```
header contents in layout main.
body contents in home index.
footer contents in layout main.

```

---

Dep packages
------------

[](#dep-packages)

- [toolkit/fsutil](https://github.com/php-toolkit/fsutil)
- [toolkit/stdlib](https://github.com/php-toolkit/stdlib)

Related
-------

[](#related)

-
-
-
-
-

License
-------

[](#license)

[MIT](LICENSE)

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance51

Moderate activity, may be stable

Popularity26

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 92.1% 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 ~59 days

Recently: every ~77 days

Total

11

Last Release

1001d ago

PHP version history (2 changes)v1.0.0PHP &gt;8.0

v1.1.0PHP &gt;=8.0.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/d23e1decaf354e8f36a7ad61128865dc78dd63336c2d023d79aa3ff8ba2a05ff?d=identicon)[inhere](/maintainers/inhere)

---

Top Contributors

[![inhere](https://avatars.githubusercontent.com/u/5302062?v=4)](https://github.com/inhere "inhere (70 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")[![iamxcd](https://avatars.githubusercontent.com/u/45652563?v=4)](https://github.com/iamxcd "iamxcd (1 commits)")

---

Tags

html-templatephprender-templaterendererrendering-enginetemplatetemplate-enginetext-template

### Embed Badge

![Health badge](/badges/phppkg-easytpl/health.svg)

```
[![Health](https://phpackages.com/badges/phppkg-easytpl/health.svg)](https://phpackages.com/packages/phppkg-easytpl)
```

###  Alternatives

[inhere/console

php console library, provide console argument parse, console controller/command run, color style, user interactive, information show.

3477.4k12](/packages/inhere-console)[inhere/php-validate

generic data validate, filter library of the php

26786.7k12](/packages/inhere-php-validate)[toolkit/pflag

Command line flag parse library of the php

3437.8k2](/packages/toolkit-pflag)[phppkg/config

Config manage, load, get. Supports INI,JSON,YAML,NEON,PHP format file

133.5k](/packages/phppkg-config)

PHPackages © 2026

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