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(2mo ago)310.8k14MITPHPPHP &gt;=8.2.0

Since Feb 13Pushed 2mo 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 1mo ago

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

54

—

FairBetter than 97% of packages

Maintenance86

Actively maintained with recent releases

Popularity25

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity75

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

73d 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

[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[whitecube/nova-flexible-content

Flexible Content &amp; Repeater Fields for Laravel Nova.

8053.0M25](/packages/whitecube-nova-flexible-content)[mopa/bootstrap-bundle

Easy integration of twitters bootstrap into symfony2

7042.9M33](/packages/mopa-bootstrap-bundle)[limenius/react-bundle

Client and Server-side react rendering in a Symfony Bundle

3871.2M](/packages/limenius-react-bundle)[nicmart/string-template

StringTemplate is a very simple string template engine for php. I've written it to have a thing like sprintf, but with named and nested substutions.

2101.7M30](/packages/nicmart-string-template)[symfony/ux-icons

Renders local and remote SVG icons in your Twig templates.

555.8M69](/packages/symfony-ux-icons)

PHPackages © 2026

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