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

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

susros/html-template-engine
===========================

HTMLTemplateEngine is an easy, simple and lightweight templating engine library for PHP.

v2.0.0(7y ago)19MITPHP

Since Nov 20Pushed 7y ago1 watchersCompare

[ Source](https://github.com/Susros/HTMLTemplateEngine)[ Packagist](https://packagist.org/packages/susros/html-template-engine)[ RSS](/packages/susros-html-template-engine/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (3)DependenciesVersions (3)Used By (0)

 [![HTML Template Engine](logo.png)](logo.png)

HTMLTemplateEngine is an easy, simple and lightweight templating engine library for PHP.

Requirement
===========

[](#requirement)

PHP Version 5.3 or higher.

Installation
============

[](#installation)

HTMLTemplateEngine can be manually downloaded or cloned by using:

```
git clone git@github.com:Susros/HTMLTemplateEngine.git

```

HTMLTemplateEngine is also available on [Packagist](https://packagist.org/packages/susros/html-template-engine). To install with composer, add this line to yoru `composer.json`:

```
"susros/html-template-engine" : "^2.0.0"

```

or just run:

```
composer require susros/html-template-engine

```

Templates
=========

[](#templates)

The extension of template files is either tpl or html. Template files are all organised in different folders called packages. In each package, there can be just template files or folders to organise or categorise template files.

Here is an example of directory structure for templates:

```
├── View
│   ├── package1
│   │   ├── **/*.tpl
│   ├── package2
│   │   ├── **/*.tpl
└── └── **/*.tpl
```

### Template Variables

[](#template-variables)

Template variable is the placeholder for the actual value. The default value can be assigned to the variable. If the default value is not declared, an empty string will be used as default value.

SyntaxDescription{$var}Variable without default value{$var : "default value"}Variable with default valueExample:

```
Hello, {$name : "World"}
{$msg}
```

### Template Function

[](#template-function)

Template functions are used to tell what actions does template engine need to do when the template is being executed. There are two functions supported.

#### dup

[](#dup)

'**dup**' template function is used to tell template engine to duplicate the template after the values are assigned to variables of the template.

SyntaxDescription{#dup : \[Template contents\] ;}Duplicate the template contentsFor example:

```

	{#dup : {$name} ;}

```

#### loop

[](#loop)

'**loop**' template function is used to tell template engine to make an 'n' copies of templates.

SyntaxDescription{#loop(n) : \[Template contents\] ;}Make n copies of template contentsFor example:

```
{#loop(5) : {$greeting} ;}
```

Usage
=====

[](#usage)

First, include the HTMLTemplateEngine class file. HTMLTemplateEngine is using namespace HTMLTemplateEngine.

```
require_once "path/to/HTMLTemplateEngine.php";
```

Before using HTMLTemplateEngine, please make sure to set the directory of template files. As default, it is set to the current directory of the application.

For example:

```
HTMLTemplateEngine::$DIRECTORY = $_SERVER["DOCUMENT_ROOT"] . "/view";
```

Then, template files can be passed through HTMLTEmplateEngine object initiator:

```
$myTemplate = new HTMLTemplateEngine("template_name.tpl");
```

You can get the template by calling package name as static method with the syntax: `HTMLTemplateEngine::PACKAGE_NAME("TEMPLATE_NAME")`

For example, to get the template1.tpl from cat1 of package1 as shown in the example above in Templates section:

```
$myTemplate = new HTMLTemplateEngine(HTMLTemplateEngine::package1("cat1/template1"));
```

Once the template engine has been initiated, you can now access template variables in template files just like accessing object's variables. Template variables can be assigned as single value or array.

If we look at the example from the Template Variables section above:

```
$myTemplate->msg = "Good Morngin!";
```

The output of template will be:

```
Hello, World
Good Morning!
```

The variable **$name** was not assigned. Therefore, default value "World" is used. The variable **$msg** is assigned with the value "Good Morngin!" and thus it is used. Otherwise, empty string will be used.

As for the template function '**dup**', it will automatically be recognised by HTMLTemplateEngine when the template is being executed with the variables values. Since we want to duplicate the template and assign with different values for each duplicated template, we need to use array in this case. For example, by using the dup template above:

```
$myTemplate->name = array(“John”, “Will”, “Josh”, “Kelvin”);
$myTemplate->id = array(1,2,3,4);
```

The output will be:

```

	John
	Will
	Josh
	Kelvin

```

Similar to '**dup**' template function, HTMLTemplateEngine will automatically recognise the function '**loop**'. It will generate the specified number of copies of the template. For example:

```
$myTemplate->greeting = "Hello, World!";
```

The output will be:

```
Hello, World!
Hello, World!
Hello, World!
Hello, World!
Hello, World!
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

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

Total

2

Last Release

2736d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/75a77e9153a1135325b1deca82ab40f3a8bc35fb15451f0e8b43eb8927e73ffe?d=identicon)[Susros](/maintainers/Susros)

---

Top Contributors

[![Susros](https://avatars.githubusercontent.com/u/18377700?v=4)](https://github.com/Susros "Susros (35 commits)")

---

Tags

html-templatephptemplate-engine

### Embed Badge

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

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

###  Alternatives

[mustache/mustache

A Mustache implementation in PHP.

3.3k44.6M291](/packages/mustache-mustache)[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)

PHPackages © 2026

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