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

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

carry0987/template-engine
=========================

Light &amp; fast php template engine, using Composer

1.3.13(2mo ago)01591MITPHPPHP &gt;=8.1

Since Oct 23Pushed 2mo agoCompare

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

READMEChangelog (10)Dependencies (6)Versions (31)Used By (1)

TemplateEngine
==============

[](#templateengine)

[![Packagist](https://camo.githubusercontent.com/d3a5441d1651a08f0437d5b9534c9ef5260b83cc18ced43a2c8d967775e5055c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6361727279303938372f74656d706c6174652d656e67696e652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/carry0987/template-engine)
A lightweight and fast PHP template engine, using Composer, featuring caching abilities, customizable cache lifetime, template inheritance, and support for Redis and MySQL.

This powerful yet simple template engine provides the flexibility to store and cache your templates in various ways. Whether you're looking to save your templates locally, cache them with longevity in mind, nest template files for complex designs, utilize persistent storage with Redis, or manage templates through MySQL databases, this engine is equipped to handle your needs efficiently and with ease.

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

[](#installation)

```
composer require carry0987/template-engine
```

Features
--------

[](#features)

- Support pure html as template
- Support CSS, JS file cache
- Support CSS model cache
- Auto minify CSS cache
- Cache lifetime

Usage
-----

[](#usage)

You can choose saving version of template file to Database or Redis

Save to the database

```
// Database configuration
$config = array(
    'host' => 'localhost',
    'port' => 3306,
    'database' => 'template',
    'username' => 'root',
    'password' => ''
);
$database = new DBController($config);
```

Save to Redis

```
// Redis configuration
$redisConfig = array(
    'host' => 'redis',
    'port' => 6379,
    'password' => '',
    'database' => 1
);
$redis = new RedisController($redisConfig);
```

Cache CSS &amp; JS File
-----------------------

[](#cache-css--js-file)

#### CSS Cache

[](#css-cache)

**Cache specific part of CSS**
html

```

```

You can use variable as `specific part`

```

```

CSS

```
/*[index]*/
.header {
    display: block;
}

.link {
    color: blue;
}
/*[/index]*/
```

Output: HTML

```

```

`cache/model_index.css`

```
/* index */
.header{display:block}.link{color:blue}
/* END index */
```

Also, with **`array`**

```

```

Or **`string`**, seperate by `,`

```

```

CSS

```
/*[index]*/
.header {
    display: block;
}

.link {
    color: blue;
}
/*[/index]*/

/*[test]*/
.header {
    display: inline-block;
}

.link {
    color: red;
}
/*[/test]*/
```

Output: HTML

```

```

`cache/model_MULTIPLE.css`

```
/* index */
.header{display:block}.link{color:blue}
/* END index */
/* test */
.header{display:inline-block}.link{color:red}
/* END test */
```

**Directly cache CSS file**
html

```

```

Output:

```

```

#### JS Cache

[](#js-cache)

html

```

```

Output:

```

```

#### Static File

[](#static-file)

html

```

```

Output:

```

```

Functions
---------

[](#functions)

#### **`echo`** function

[](#echo-function)

html

```
{$value}
```

PHP

```

```

#### **`assign variable`** function

[](#assign-variable-function)

> Note: don't put any php script into **`block`** tag

html

```

html content

```

PHP

```

```

#### **`if`** function

[](#if-function)

html

```

    statement1

    statement2

    statement3

```

PHP

```

    statement1

    statement2

    statement3

```

#### **`loop`** function (without key)

[](#loop-function-without-key)

html

```

    username

```

PHP

```

    username

```

#### **`loop`** function (with key)

[](#loop-function-with-key)

html

```

    {$key} = {$value}

```

PHP

```

     =

```

#### **`eval`** function

[](#eval-function)

html

```

{$value}
```

PHP

```

```

**`PRESERVE`** mark
-------------------

[](#preserve-mark)

html

```

html content

/*{PRESERVE}*/

const value = 1+2;
document.querySelector('span').innerHTML = `Value: ${value}`;

/*{/PRESERVE}*/
```

PHP

```
html content

const value = 1+2;
document.querySelector('span').innerHTML = `Value: ${value}`;

```

###  Health Score

45

—

FairBetter than 92% of packages

Maintenance87

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity62

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

Recently: every ~148 days

Total

30

Last Release

66d ago

PHP version history (3 changes)1.0.0PHP &gt;=7.2

1.2.3PHP &gt;=8.0

1.2.8PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/1f43bad259478092c4ff269518aa9a0c8e91a537a67272877041b4bc1f25cfe8?d=identicon)[carry0987](/maintainers/carry0987)

---

Top Contributors

[![carry0987](https://avatars.githubusercontent.com/u/12984973?v=4)](https://github.com/carry0987 "carry0987 (51 commits)")

---

Tags

pdophp8redistemplate-enginexxhashtemplatetemplate engineengine

### Embed Badge

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

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

###  Alternatives

[latte/latte

☕ Latte: the intuitive and fast template engine for those who want the most secure PHP sites. Introduces context-sensitive escaping.

1.3k15.7M683](/packages/latte-latte)[anourvalar/office

Generate documents from existing Excel &amp; Word templates | Export tables to Excel (Grids)

24085.2k](/packages/anourvalar-office)[templavoilaplus/templavoilaplus

Building kit for custom pages and content elements with individual fields, containers and backend layouts. Supporting drag'n'drop and multiple references.

2637.6k13](/packages/templavoilaplus-templavoilaplus)[talesoft/tale-pug

A clean, lightweight and easy-to-use templating engine for PHP based on Pug, formerly Jade

319.4k3](/packages/talesoft-tale-pug)[leitsch/kirby-blade

Enable Laravel Blade Template Engine for Kirby 4 and Kirby 5

219.2k](/packages/leitsch-kirby-blade)

PHPackages © 2026

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