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

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

mezon/template-engine
=====================

Small template engine for your projects

1.0.9(3mo ago)310.8k14MITPHPPHP &gt;=8.2.0CI failing

Since Feb 13Pushed 3mo ago2 watchersCompare

[ Source](https://github.com/alexdodonov/mezon-template-engine)[ Packagist](https://packagist.org/packages/mezon/template-engine)[ Docs](https://github.com/alexdodonov/mezon-template-engine)[ RSS](/packages/mezon-template-engine/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (10)Versions (11)Used By (4)

Template engine
===============

[](#template-engine)

[![Open Collective](https://camo.githubusercontent.com/a2b15f8e2268d4e3842e00d41ff7a57cce2ad8bd8d8769c5dc4fa05a546a4f62/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4f70656e253230436f6c6c6563746976652d73706f6e736f722d3765616466313f6c6f676f3d6f70656e253230636f6c6c656374697665266c6f676f436f6c6f723d376561646631266c6162656c436f6c6f723d353535353535)](https://opencollective.com/mezon-router) [![codecov](https://camo.githubusercontent.com/64f4b5c1998d46d4da31c28744fd0fc28ffded850972a2fa0b02ef1dcda5d013/68747470733a2f2f636f6465636f762e696f2f67682f616c6578646f646f6e6f762f6d657a6f6e2d74656d706c6174652d656e67696e652f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d32585478436e5a746646)](https://codecov.io/gh/alexdodonov/mezon-template-engine)

Intro
-----

[](#intro)

Template engine provides template compilation routine with variables, loops and other programming abstractions.

Loading resources
-----------------

[](#loading-resources)

Mezon has a simple storage wich stores CSS and JS files. When page is rendered, template engine accessing it and fetching files to put in the 'head' tag of the rendered page.

Storage is globally accessed. So any componen can add it's own resources to the page.

It can be done in this way:

```
$TemplateResources = new TemplateResources(); // getting access to the global storage

$TemplateResources->add_css_file( './res/test.css' ); // additing CSS file
$TemplateResources->add_js_file( './include/js/test.js' ); // additing JS file

$TemplateResources->add_css_files(
    [ './res/test1.css' , './res/test2.css' ]
); // additing CSS files
$TemplateResources->add_js_files(
    [ './include/js/test1.js' , './include/js/test2.js' ]
); // additing JS files
```

Resource storage is quite intilligent so you can't add many files with the same paths.

```
$TemplateResources = new TemplateResources(); // getting access to the global storage

$TemplateResources->add_css_file( './res/test.css' ); // additing CSS file
$TemplateResources->add_css_file( './res/test.css' ); // no file will be added
```

But this way of additing resources is quite low level and it may be inconvinient for large number of resource files. So we have created assets. The documentation about it can be read [here](https://github.com/alexdodonov/mezon/tree/master/vendor/asset#assets-with-css-and-js-files)

Page compilation
----------------

[](#page-compilation)

TemplateEngine class provides content compilation routine. This function is called TemplateEngine::print\_record( $String , $Data ) wich replaces all variables {variable-name} with values from $Data.

```
// outputs "v1 v2"
print( TemplateEngine::print_record(
    '{var1} {var2}' , [ 'var1' => 'v1' , 'var2' => 'v2' ]
) );

// or object
$Object = new stdClass();
$Object->var1 = 'v1';
$Object->var2 = 'v2';

// outputs "v1 v2"
print( TemplateEngine::print_record(
    '{var1} {var2}' , $Object
) );

// $Data may contain nested arrays or objects
// outputs "v1 v2 v3"
print( TemplateEngine::print_record(
    '{var1} {var2} {var3}' , [ $Object , [ 'var3' => 'v3' ] ]
) );
```

Template variables
------------------

[](#template-variables)

You can use template variables bounded by '{' and '}' symbols.

For example:

Extended page compilation
-------------------------

[](#extended-page-compilation)

You may also use loopes in your templates.

For example:

```
$Engine = new TemplateEngine();
$Engine->set_page_var( 'var1' , 'value1' );
$Engine->set_page_var( 'var2' , 'value2' );

$Content = '{var1} & {var2}';
print( $Engine->compile_page_vars( $Content ) ); // outputs "value1 value2"
```

And the output will be:

```
row : 1
row : 2
row : Last
```

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance78

Regular maintenance activity

Popularity25

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 95.7% 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 ~246 days

Recently: every ~432 days

Total

10

Last Release

118d ago

PHP version history (2 changes)1.0.0PHP &gt;=7.2.0

1.0.9PHP &gt;=8.2.0

### Community

Maintainers

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

---

Top Contributors

[![alexdodonov](https://avatars.githubusercontent.com/u/14943896?v=4)](https://github.com/alexdodonov "alexdodonov (45 commits)")[![lolix-notepad](https://avatars.githubusercontent.com/u/75387306?v=4)](https://github.com/lolix-notepad "lolix-notepad (2 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[limenius/react-bundle

Client and Server-side react rendering in a Symfony Bundle

3851.2M](/packages/limenius-react-bundle)[area17/laravel-auto-head-tags

Laravel Auto Head Tags helps you build the list of head elements for your app

4616.1k](/packages/area17-laravel-auto-head-tags)[jelix/wikirenderer

WikiRenderer is a library to generate HTML or anything else from wiki content.

1712.3k1](/packages/jelix-wikirenderer)[webkinder/sproutset

A Composer package for handling responsive images in Roots Bedrock + Sage + Blade projects.

282.2k](/packages/webkinder-sproutset)

PHPackages © 2026

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