PHPackages                             coercive/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. [Templating &amp; Views](/categories/templating)
4. /
5. coercive/template

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

coercive/template
=================

Coercive Utility for building template from array data

0.0.0(1y ago)15MITPHP &gt;=7.4

Since Jan 20Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Coercive/Template)[ Packagist](https://packagist.org/packages/coercive/template)[ Docs](http://coercive.fr)[ RSS](/packages/coercive-template/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Template
========

[](#template)

Build template from array data (so from converted Yaml or Json too)

Get
---

[](#get)

```
composer require coercive/template

```

Array structure
---------------

[](#array-structure)

Please see `/sample/example.xml`

The field `wrapper` is use to place some html arround your content.

Set `{{content}}` inside the `wrapper` where your want to place your content.

The field `content` will be injected there.

You can also don't use it and place everything you need inside the `wrapper` directly.

The other fields `id`, `type`, `class` ... are setted to do checks, loops, inject specific content for a given id etc...

Basic load
----------

[](#basic-load)

```
use Coercive\Utility\Template\ArrayLoader;

# ArrayLoader returns multiple template, so if only one we take it by using [0] (the first row in array).
$template = ArrayLoader::load([$mapped])[0] ?? null;

# If you need to use some methods based on a map system, you have to load maps by using automap method.
if($template) {
    $template->automap();
}

# Render the template
echo $template->getHtml();
```

Useful methods
--------------

[](#useful-methods)

Apply automaticaly the tag {{content}} to main template wrapper that don't have one.

```
$template->setDefaultContentWrapperIfEmpty();
```

Apply automaticaly the tag {{content}} to positions wrapper that don't have one, and match the given types.

```
$template->setDefaultContentWrapperForAllByTypes(['your_first_type_to_check', 'your_second_type_to_check']);
```

Work with types, ids, classes, namespaces, or all (no extra-check).

---

You have lot's of getters and setters to retrieve or set some data

```
# See constant options on top of the class.
echo $template->getInternalId();
echo $template->getInternalClass();
echo $template->getInternalNamespace();
echo $template->getInternalType();
```

Access to data field. *(use Coercive/Container)*

```
echo $template->data()->get('something');
```

---

Inject custom blocks that require internal preparation by your system.

```
foreach ($template->getPositionByType('custom') as $position) {
    if($position->data()->get('item_type') === 'SLIDE' && $code = (int) $position->data()->get('item_code')) {
        $slide = $$$_Get_Your_Data_Here_For_Example($code);
        if($slide) {
            $html = $$$_Get_Render_System_Here_For_Example('template/example/slide', ['slide_data' => $slide]);
            $position->setWrapper($html); // or setContent() if you have a wrapper to use
        }
    }
}
```

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance42

Moderate activity, may be stable

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity28

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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

483d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/20288080?v=4)[Coercive](/maintainers/Coercive)[@Coercive](https://github.com/Coercive)

---

Top Contributors

[![Coercive](https://avatars.githubusercontent.com/u/20288080?v=4)](https://github.com/Coercive "Coercive (3 commits)")

### Embed Badge

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

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

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M2.6k](/packages/craftcms-cms)[tightenco/jigsaw

Simple static sites with Laravel's Blade.

2.2k438.5k29](/packages/tightenco-jigsaw)[endroid/qr-code-bundle

Endroid QR Code Bundle

32110.6M17](/packages/endroid-qr-code-bundle)[webuni/front-matter

Front matter parser and dumper for PHP

41264.9k11](/packages/webuni-front-matter)[symfony/ux-toolkit

A tool to easily create a design system in your Symfony app with customizable, well-crafted Twig components

1432.0k](/packages/symfony-ux-toolkit)[iq2i/storia-bundle

UI Storia bundle

144.6k](/packages/iq2i-storia-bundle)

PHPackages © 2026

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