PHPackages                             hokoo/templater - 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. hokoo/templater

ActiveLibrary

hokoo/templater
===============

Keep your templates in one place apart from your php code.

v4.1(1y ago)31.1k[1 issues](https://github.com/hokoo/templater/issues)GPL-3.0-onlyPHPCI passing

Since Jan 5Pushed 1y ago1 watchersCompare

[ Source](https://github.com/hokoo/templater)[ Packagist](https://packagist.org/packages/hokoo/templater)[ RSS](/packages/hokoo-templater/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (1)Versions (22)Used By (0)

Anatomy: a templater for PHP
============================

[](#anatomy-a-templater-for-php)

[![Latest Stable Version](https://camo.githubusercontent.com/7fdaea58d285d3d288fb12aab45fdd1db703b16d3f1a8cda666afbedbb3cdb7e/68747470733a2f2f706f7365722e707567782e6f72672f686f6b6f6f2f74656d706c617465722f76)](//packagist.org/packages/hokoo/templater)[![PHPUnit Tests](https://github.com/hokoo/templater/actions/workflows/phpunit.yml/badge.svg)](https://github.com/hokoo/templater/actions/workflows/phpunit.yml)

HTML Templater for PHP.

[![Anatomy logo](assets/anatomy-logo.png)](assets/anatomy-logo.png)

Lightweight, simple but powerful templater for rendering HTML templates in PHP.

I believe that you'd like to

- keep your HTML clean and simple, and
- maintain the logic in PHP, not in HTML.

Table of Contents
-----------------

[](#table-of-contents)

- [Requirements](#requirements)
- [Installation](#installation)
- [Getting Started](#getting-started)
    - [Tags](#a-tags)
    - [Predefined tags](#a-predefined-tags)
    - [Blocks &amp; Containers](#a-blocks--containers)
    - [Detached mode](#a-detached-mode)
- [Back compatibility](#back-compatibility)

Requirements
------------

[](#requirements)

PHP 8.0 and later.

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

[](#installation)

```
composer require hokoo/templater
```

Getting Started
---------------

[](#getting-started)

Here are some examples of how to use the templater.

### 🅰️ Tags

[](#a-tags)

#### Example:

[](#example)

```

        {{title}}

        {{content}}

```

#### PHP code:

[](#php-code)

```
use iTRON\Anatomy\Templater;
$templater = new Templater();

return $templater->render( $html, [
    'title'   => 'The Best Title',
    'content' => 'Anything you want',
] );
```

#### The result will be:

[](#the-result-will-be)

```

        The Best Title

        Anything you want

```

Read more theory about TagsTag - a point in the template where you can insert a value. Tag should be considered as a placeholder for a value.

```
In the Anatomy's paradigm, the 'tag' is only entity that can be replaced with a value.

```

The tag is a string that starts with `{{` and ends with `}}`.

So, in the example above, the `{{title}}` and `{{content}}` are tags. Let's render the template with the values.

### 🅰️ Predefined tags

[](#a-predefined-tags)

#### Example:

[](#example-1)

```

```

#### PHP code:

[](#php-code-1)

```
$templater = new \iTRON\Anatomy\Templater();

$result = $templater->render( $html, [
    'class' => 0,
] );
```

#### The result will be:

[](#the-result-will-be-1)

```

```

Read more theory about Predefined TagsPredefined tags are tags that can render only values predefined by the template. Predefined tag's modifier can only accept an integer value as index of one of the predefined values (starting from 0). Any invalid modifier value (non-integer or integer that points beyond of the array) will be considered as 0.

The default values' delimiter is `|`. You can change it by setting the `delimiter` property of the tag.

```

```

### 🅰️ Blocks &amp; Containers

[](#a-blocks--containers)

#### Example:

[](#example-2)

```

    {{title}}

    {{content}}

    [[#article]]

        {{title}}

            {{content}}

    [[/article]]

```

#### PHP code:

[](#php-code-2)

```
// This is a container.
// It can contain blocks and texts.
$content = new \iTRON\Anatomy\Container();

// Let's put block "article" into the container.
$content->addBlock( 'article', [
    'title'   => 'The Best Title',
    'content' => 'Anything you want',
] );

// Another one.
$content->addBlock( 'article', [
    'title'   => 'There is no title',
    'content' => 'There is no content.',
] );

// Or you can add a plain text.
$content->addText( 'Plain text.' );

$templater = new iTRON\Anatomy\Templater();

return $templater->render( $html, [
    'title'   => "Feed's Title",
    'content' => $content
] );
```

#### The result will be:

[](#the-result-will-be-2)

```

    Feed's Title

        The Best Title

            Anything you want

        There is no title

            There is no content.

    Plain text.

```

Read more theory about Blocks &amp; ContainersBlocks are a way to have a component-like structure in the template. You can consider blocks as a template inside a template.

You can define as many blocks as you want and render them in any order.

You can put one block into another block. This is how you can create a nested structure without any restrictions on the depth of nesting.

### 🅰️ Detached mode

[](#a-detached-mode)

Since we consider blocks as an almost independent template, you can use blocks out of context of the main template.

Suppose, you need to render the "article" block from the template above in a different place. Great, there's no need to duplicate the block's code. Just render the block separately.

```
$templater = new \iTRON\Anatomy\Templater();

echo $templater->renderBlock(
    $html,
    'article',
    [
      'title' => 'Title',
      'content' => 'Content'
    ]
);
```

The result would be:

```

    Title

        Content

```

Back compatibility
------------------

[](#back-compatibility)

Version 3 is still supported. Syntax of the older versions is not supported anymore.

To use v3 syntax, you have to instantiate the legacy version of the templater:

```
$templater = new \iTRON\Templater\Templater();

// Instead of
// $templater = new \iTRON\Anatomy\Templater();
```

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance41

Moderate activity, may be stable

Popularity21

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

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

Recently: every ~58 days

Total

8

Last Release

397d ago

Major Versions

2.0 → v3.0.x-dev2024-08-26

3.1 → v4.02025-03-08

### Community

Maintainers

![](https://www.gravatar.com/avatar/3988fe121d93b3ce7fb819c278cf7f19bf40411db2a1a57bbd4ae6ea4ca3eedc?d=identicon)[hokoo](/maintainers/hokoo)

---

Top Contributors

[![hokoo](https://avatars.githubusercontent.com/u/16269260?v=4)](https://github.com/hokoo "hokoo (99 commits)")

---

Tags

html-templatephp-html

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/hokoo-templater/health.svg)

```
[![Health](https://phpackages.com/badges/hokoo-templater/health.svg)](https://phpackages.com/packages/hokoo-templater)
```

PHPackages © 2026

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