PHPackages                             ppajer/php-datatemplate - 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. ppajer/php-datatemplate

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

ppajer/php-datatemplate
=======================

A lightweight library for rendering HTML templates in a clean way.

012PHP

Since May 31Pushed 5y ago1 watchersCompare

[ Source](https://github.com/ppajer/PHP-DataTemplate)[ Packagist](https://packagist.org/packages/ppajer/php-datatemplate)[ RSS](/packages/ppajer-php-datatemplate/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

PHP-DataTemplate
================

[](#php-datatemplate)

A lightweight library for rendering HTML templates in a clean way.

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

[](#installation)

Either install via Composer or download this repository and include the class in your project manually.

Usage
-----

[](#usage)

The template takes a HTML file and a PHP array as inputs, and works by replacing strings inside the defined template tags with data from the input array with the same key. For example, `{{email}}` will be replaced by the contents of `$data['email']`.

### Initialization

[](#initialization)

The constructor accepts 3 arguments: The name of the template file to use, the root path of the template directory (optional, default: `'./templates'`) and an array of opening and closing tags to fill in your template (optional, defaults to `['{{','}}'}`).

```

$template = 'item.html';
$baseDir = dirname(__FILE__).'/tpl';
$template = new DataTemplate($template, $baseDir);

```

### Rendering a template

[](#rendering-a-template)

Once your instance is ready, you can call the `render()` method, passing in the data to be rendered as argument.

```
$data = [
  'foo' => 'hello',
  'bar' => 'world'
];
$template = new DataTemplate($template, $baseDir);
$html = $template->render($data);

```

#### Nested templates

[](#nested-templates)

To nest templates inside other templates, simply put the name of the template inside the template tags. For example, `{{partial.html}}` will render the contents of `partial.html` to replace the tag.

#### Repeating templates

[](#repeating-templates)

To repeat a partial template, simply prefix it with a `*` and pass an array as its value inside `$data`. For example, `{{*item.html}}` will render the contents of `item.html` as many times as there are elements in the `$data['item.html']` array.

```

```

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

 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.

### Community

Maintainers

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

---

Top Contributors

[![ppajer](https://avatars.githubusercontent.com/u/5861559?v=4)](https://github.com/ppajer "ppajer (5 commits)")

### Embed Badge

![Health badge](/badges/ppajer-php-datatemplate/health.svg)

```
[![Health](https://phpackages.com/badges/ppajer-php-datatemplate/health.svg)](https://phpackages.com/packages/ppajer-php-datatemplate)
```

###  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)
