PHPackages                             phplater/phplater - 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. phplater/phplater

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

phplater/phplater
=================

A simple PHP template engine that lets PHP do most the logic and then append it to the HTML in the template file.

v1.1.1(3y ago)316MITPHPPHP &gt;=8.0

Since May 5Pushed 3y ago1 watchersCompare

[ Source](https://github.com/ThaKladd/PHPlater)[ Packagist](https://packagist.org/packages/phplater/phplater)[ Docs](https://github.com/ThaKladd/PHPlater)[ RSS](/packages/phplater-phplater/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (25)Used By (0)

PHPlater
========

[](#phplater)

A simple PHP template engine that aims for PHP do most of the logic(even if some logic is supported in the engine) and then append it to the HTML in the template file. It is set to solve the problem of mixing too much logic into the template file itself and by that loosing some control over where the logic happens. Some of the syntax is also unique, and the engine itself is very lightweight. You also get a bit more control over the data that is passed down to the template, and the code is easier to manage and to track.

Why?
----

[](#why)

As a backend developer, I want to do most of the logic in PHP, and when to seperate HTML out from the code, I usually need a simple variable to value replacement tool. In its simplest form, its just a str\_replace, but soon you find that you need something a little bit more powerfull, although still simple. PHPlater is aimed to solve this, that most of the values and logic should still be done in pure PHP, but then in order for the view to be as much pure HTML as possible to introduce a simple syntax for the most common operations. So, in a nutshell, PHPlater gives you variables with filters, lists and conditionals, with the simplicity of the syntax in mind as well as ease of use without any other dependencies. Every coder is different, and this was made to solve my way of doing it. Maybe there are someone else that finds it attractive too?

---

- [Installation](#installation)
- [Simple Usage](#simple-usage)
- [Advanced Usage](#advanced-usage)
- [Tags](#tags)
- [Test](#test)
- [Contributing](#contributing)
- [Documentation](#documentation)
- [License](#licence)

---

Installation
------------

[](#installation)

PHP 8.0 or higher is needed for this class to work.

Use the package manager [composer](https://getcomposer.org/) to install PHPlater.

```
composer require phplater/phplater
```

Simple Usage
------------

[](#simple-usage)

### Given this PHP code

[](#given-this-php-code)

```
$phplater = new PHPlater();
$phplater->setPlate('hello', 'world!');
echo $phplater->render('Hello {{hello}}');
```

### This will be the output

[](#this-will-be-the-output)

```
Hello world!
```

Advanced Usage
--------------

[](#advanced-usage)

Some more examples are available under [/examples](https://github.com/ThaKladd/PHPlater/tree/master/examples) and [/tests](https://github.com/ThaKladd/PHPlater/tree/master/tests)

### Given this template.tpl file

[](#given-this-templatetpl-file)

```

    One: {{ one }}
    Two: {{ two.getTwo }}
    Three: {{ assoc.three }}
    Four: {{ assoc.4 }}
    Five: {{ assoc.5.0 }}
    Six: {{ assoc.six.0 }}
    Seven: {{ seven_obj.returnArray.seven }}

```

### And this PHP code

[](#and-this-php-code)

```
class Test {
    function getTwo() {
        return 'Kaksi';
    }
    public function returnArray() {
        return ['seven' => 'Seitsemän'];
    }
}

$phplater = new PHPlater();
$phplater->setPlates([
    'one' => 'Yksi',
    'two' => new Test(),
    'assoc' => [
        'three' => 'Kolme',
        4 => 'Neljä',
        5 => ['Viisi'],
        'six' => ['Kuusi']
    ],
    'seven_obj' => new Test()
]);

echo $phplater->render('template.tpl');
```

### This will then be the output

[](#this-will-then-be-the-output)

```

    One: Yksi
    Two: Kaksi
    Three: Kolme
    Four: Neljä
    Five: Viisi
    Six: Kuusi
    Seven: Seitsemän

```

### Many

[](#many)

In order to ease the looping a array of similar values, it can be sent inn and iterated over on the same template

### Given this code

[](#given-this-code)

```
$phplater = new PHPlater();
$phplater->setMany(true)->setPlates([
    ['value' => ['this']],
    ['value' => ['is']],
    ['value' => ['ok']]
]);
echo ''.$phplater->render('{{ value.0 }}').'';
```

### The output will be as follows

[](#the-output-will-be-as-follows)

```
thisisok
```

There is also a syntax for doing a foreach inside the template using tags and a placeholder without the many method

### Given this

[](#given-this)

```
$phplater = new PHPlater();
$phplater->setPlates([
    'list' => [
        ['value' => ['this']],
        ['value' => ['is']],
        ['value' => ['ok']]
    ]
]);
echo $phplater->render('[[{{ list..value.0 }}]]');
```

### The output wil be like this

[](#the-output-wil-be-like-this)

```
thisisok
```

### Filters

[](#filters)

Filters gets inspiration from [Twig](https://github.com/twigphp/Twig) and and come after | tag with arguments to the method inspired by [Latte](https://github.com/nette/latte)

### If code is like this

[](#if-code-is-like-this)

```
$phplater = new PHPlater();
$phplater->setFilter('uppercase', 'mb_strtoupper');
$phplater->setFilter('add_ok', function (string $data, string $ok = '') {
    return $data . ' is '.$ok;
});

$phplater->setPlate('string', 'test');

echo $phplater->render('This {{string|add_ok:ok|uppercase}}');
```

### The html results in

[](#the-html-results-in)

```
This TEST IS OK
```

### Conditionals

[](#conditionals)

The conditional evaluates one or two variables, and return either a true value or a false value. These must have a space before and after the operator and the syntax is as follows.

```
$phplater = new PHPlater();
$phplater->setPlates([
    'arr' => ['check', 'check', 'true', 'false']
]);
echo $phplater->render('(( {{ arr.0 }} == {{ arr.1 }} ?? {{ arr.2 }} :: {{ arr.3 }} ))');
```

### And the output will be

[](#and-the-output-will-be)

```
true
```

These are the supported comparison operations

OperatorDescription==Equal!=Not equal!==Strict not equal===Strict equal&gt;=Greater than or equal&lt;=Less than or equal&gt;Greater than&lt;Less than&lt;&gt;Not equal&lt;=&gt;Spaceship operator%Modulo, reminder (0 is falsy)&amp;&amp;AndandAnd||OrorOrxorEither, but not bothTags
----

[](#tags)

There are a minimal amount of tags to remeber in PHPlater, and almost all of them are changeable

TagDescriptionExample{{ and }}Start and end tag for template variable`{{var}}`.Chain separator by which to traverse plates`{{root.var}}`|Filter tag to variable, method followes`{{var``|``method}}`:Seperator if filter method need arguments`{{var``|``method:arg1}}`,Seperate the arguments given to method`{{var``|``method:arg1,arg2}}`\[\[ and \]\]Start and end tag for each element in a list`[[{{var}}]]`\#To get the key from list`[[{{ # }}]]`..Placement of list in the variable chain`[[{{list..var}}]]`(( and ))Start and end tag for conditional expression`(( {{var}} ?? true :: false ))`??Tag after condition, followed by true result`(( {{var}} ?? true ))`::Tag after true result, followed by false result`(( {{var}} ?? :: false ))`~Default preg delimiterTest
----

[](#test)

### PHPUnit

[](#phpunit)

PHPUnit 9.5.21 is used. Download [phpunit.phar](https://phar.phpunit.de/) and, in the root folder of the project, run tests with

```
php c:/path/to/phpunit.phar
```

For code coverage, add " --coverage-text" to the command, and use [xDebug](https://xdebug.org/download) or similar of your choice.

Other tools like [psalm](https://github.com/vimeo/psalm) and [PHPStan](https://github.com/phpstan/phpstan/) are used as well for testing to find errors.

### Psalm

[](#psalm)

```
c:/path/to/vendor/bin/psalm --show-info=true --no-cache
```

### PHPStan

[](#phpstan)

```
c:/path/to/vendor/bin/phpstan analyse src --level=9
```

Contributing
------------

[](#contributing)

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Issues to fix and features to add
---------------------------------

[](#issues-to-fix-and-features-to-add)

At the moment, very few - although more rewriting is needed.

Documentation
-------------

[](#documentation)

[PHPDocumentator](https://phpdoc.org/) v.3.3.1 is used for generating documentation from PHPDoc in code. Download [phpDocumentor.phar](https://phpdoc.org/phpDocumentor.phar) and run the following in the project folder to update it.

```
php c:/path/to/phpDocumentor.phar -d src -t docs
```

License
-------

[](#license)

[MIT](https://choosealicense.com/licenses/mit/)

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

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

Recently: every ~22 days

Total

13

Last Release

1313d ago

Major Versions

v0.8.0 → v1.0.02022-08-26

### Community

Maintainers

![](https://www.gravatar.com/avatar/370ccff30abcfaa260db70f24bb9bda3a43898adb0b1e3957b904812516b2228?d=identicon)[ThaKladd](/maintainers/ThaKladd)

---

Top Contributors

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

---

Tags

phptemplatetemplatingtemplatestemplate enginetplphp templates

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Type Coverage Yes

### Embed Badge

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

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

###  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)
