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

ActiveLibrary

mezon/html-template
===================

Small html-template script

1.1.13(2mo ago)49.8k14MITPHPPHP &gt;=8.2.0

Since Feb 20Pushed 2mo ago2 watchersCompare

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

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

HTML template class
===================

[](#html-template-class)

[![Build Status](https://camo.githubusercontent.com/b30321d4b515cca281fddbaab09f33fbc62f044b4014e583cf16d9ef062266d2/68747470733a2f2f7472617669732d63692e636f6d2f616c6578646f646f6e6f762f6d657a6f6e2d68746d6c2d74656d706c6174652e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/alexdodonov/mezon-html-template) [![codecov](https://camo.githubusercontent.com/6b935a1f582c62ecdd40a9b7e9bf40299e8d98710ec35d42025298d14f977407/68747470733a2f2f636f6465636f762e696f2f67682f616c6578646f646f6e6f762f6d657a6f6e2d68746d6c2d74656d706c6174652f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/alexdodonov/mezon-html-template) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/93e7bbda669bf36ddf95e0676a950a4c0025cd1b5c4e1d4ca9fea0296a5fe910/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f616c6578646f646f6e6f762f6d657a6f6e2d68746d6c2d74656d706c6174652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/alexdodonov/mezon-html-template/?branch=master)

This class provides routine for HTML pages generation. Works fast and quite simple in use.

It is a part of [Mezon Framework](https://github.com/alexdodonov/mezon) and used in the [Application class](https://github.com/alexdodonov/mezon-common-application)

Learn more
==========

[](#learn-more)

More information can be found here:

[Twitter](https://twitter.com/mezonphp)

[dev.to](https://dev.to/alexdodonov)

I'll be very glad if you'll press "STAR" button )
=================================================

[](#ill-be-very-glad-if-youll-press-star-button-)

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

[](#installation)

Just type

```
composer require mezon/html-template

```

Usage
-----

[](#usage)

### Paths to template files

[](#paths-to-template-files)

First of all you need to create object.

```
use Mezon\HtmlTemplate\HtmlTemplate;

$template = new HtmlTemplate('./main-template/');
```

This code assumes that you have all template resources in the directory `./main-template/`.

But you can also specify a list of paths, and while template compilation they all will be scanned for template files.

```
$template = new HtmlTemplate(['./main-template/', './extra-files/res/']);
```

No need to specify all paths in the constructor. You can do it later with methods:

```
$template = new HtmlTemplate('./main-template/');
$template->addPaths(['./path1', './path2']);
```

But be carefull if you have static files with the same names on different paths. While compilation the file on the latest added path will be used. It was done so to create a sort of overriding mechanism for template resources.

Or you can completely reset all paths:

```
$template->setPaths(['./path1', './path2']);
```

And view a list of paths:

```
var_dump($template->getPaths());
```

### Setup layout

[](#setup-layout)

You can have different layouts for your pages:

```
$template = new HtmlTemplate(%template-sources%, 'index');
// or 'form' instead of 'index', or '404', or '403' etc.
```

Layout will let you to define different templates for your different purposes.

You can create in your template as much layouts as you need. Just add files:

```
%template-sources%/Res/Templates/infex.html
%template-sources%/Res/Templates/form.html
%template-sources%/Res/Templates/404.html
%template-sources%/Res/Templates/403.html
// and so on

```

### Setup blocks

[](#setup-blocks)

After the layout was setup you can pass blocks to the template.

It will allow you to put different content in your layout.

For example:

```
$template->addBlock('hello-world');
```

That means that `HtmlTemplate` class will get the file `%template-sources%/Res/Blocks/%block-name%.tpl` and put instead the placeholder `{%block-name%}` within your layout.

But you can place the block in any placeholder you need:

```
HtmlTemplate::setPageVarFromBlock(string $var, string $blockName);
// here is $var is the name if your placeholder within the layout
// and $blockName is %template-sources%/Res/Blocks/$blockName.tpl
```

If you have `$var=foo` then your placeholder must be {foo}

### Setting vars

[](#setting-vars)

You can also pass almost any data to the template

```
// here is $value is a scalar value or object wich implements __toString method
// and $var is a name of your placeholder within the layout
setPageVar(string $var, $value): void;

// this method can be used if you need to place file's $path content in your layout
setPageVarFromFile(string $var, string $path): void;

// you can set multyple vars with one call
// here $vars is an assoc array
setPageVars(array $vars): void;
```

### Compile template

[](#compile-template)

Just call

```
compile(): string
```

The method will return a compiled page wich you can send to user of your application.

###  Health Score

55

—

FairBetter than 98% of packages

Maintenance86

Actively maintained with recent releases

Popularity26

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 92.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 ~110 days

Recently: every ~388 days

Total

21

Last Release

73d ago

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

1.1.13PHP &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 (38 commits)")[![lolix-notepad](https://avatars.githubusercontent.com/u/75387306?v=4)](https://github.com/lolix-notepad "lolix-notepad (3 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

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

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

PHPackages © 2026

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