PHPackages                             chrissileinus/template-php - 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. chrissileinus/template-php

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

chrissileinus/template-php
==========================

A template engine to generate strings from a template. Also it is possible to colorize parts with ANSI codes with the help of the ansiPHP class.

0.1.0(4y ago)0221MITPHP

Since Mar 17Pushed 4y ago1 watchersCompare

[ Source](https://github.com/chrissileinus/templatePHP)[ Packagist](https://packagist.org/packages/chrissileinus/template-php)[ RSS](/packages/chrissileinus-template-php/feed)WikiDiscussions master Synced 6d ago

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

templatePHP
===========

[](#templatephp)

A template engine to generate strings from a template. It is also prossible to colorize parts with ANSI codes with the help of the [ansiPHP](https://gitlab.com/chrissileinus/ansiPHP) class.

Why
---

[](#why)

On the search of a simple template engine to generate some output on the bash i found [nicmart/StringTemplate](https://github.com/nicmart/StringTemplate). But in the need for static callable methods with colorizing features, I decided to write something similar.

Usage
-----

[](#usage)

### placeholders

[](#placeholders)

Placeholders are delimited by default by `{` and `}`, but you can specify others by `Str::placeholders()`.

```
Chrissileinus\Template\Str::placeholders('a', 'b');
```

### replace

[](#replace)

If array key is not specified then write the index into the template.

```
// @returns string: "This is my value: nic"
Chrissileinus\Template\Str::replace("This is my value: {0}", ['nic']);
```

With specified keys are practical on longer templates.

```
// @returns string: "My name is Christian Backus"
Chrissileinus\Template\Str::replace(
  "My name is {name} {surname}",
  [
    'name' => 'Christian',
    'surname' => 'Backus'
  ]
);
```

You are also able to access nested arrays.

```
// @returns string: "My name is Christian and her name is Aline"
Chrissileinus\Template\Str::replace(
  "My name is {my.name} and her name is {her.name}",
  [
    'my' => ['name' => 'Christian'],
    'her' => ['name' => 'Aline']
  ]
);
```

You are also able to submit several arrays. All arrays get merged by `array_replace_recursive` with the given order.

```
// @returns string: "My name is Christian and her name is Aline"
Chrissileinus\Template\Str::replace(
  "My name is {my.name} and her name is {her.name}",
  [
    'my' => ['name' => 'Christian']
  ],
  [
    'her' => ['name' => 'Aline']
  ]
);
```

### replaceFormat | replaceF

[](#replaceformat--replacef)

With the usage of sprintf we are able to use the [convertion specifications](https://www.php.net/manual/en/function.sprintf.php) for the placeholders.

```
// @returns string: "My name is chris and my age is 041 [ 83.40]"
Chrissileinus\Template\Str::replaceFormat(
  "My name is {user.name} and my age is {age%03d} [{weight%6.2f}]",
  [
    'user' => [
      'name' => "chris"
    ],
    'age' => 41,
    'weight' => 83.4,
  ]
);
```

Additionally we also able to colorize the result with the ANSI Commands. Helpful for output in terminal applications.

Just a additional `&` and a list of color and styling commands. They can also be spezified in the input array.

```
// @returns string: "My name is chris and my age is 041 [ 83.40]"
Chrissileinus\Template\Str::replaceFormat(
  "My name is {user.name&user.color} and {my&user.color} age is {age&f_blue} {[{weight%6.2f}]&test.style}",
  [
    'user' => [
      'name' => "chris"
    ],
    'age' => 41,
    'weight' => 83.4,
  ],
  [
    'user' => [
      'color' => "f_yellow"
    ],
    'test' => [
      'style' => "bold,f_magenta"
    ]
  ]
);
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity38

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

1520d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5bd509356cb018db17d5d6ba969f10acabec3926c4c92aa88d5702a6a665bcac?d=identicon)[chrissileinus](/maintainers/chrissileinus)

---

Top Contributors

[![chrissileinus](https://avatars.githubusercontent.com/u/62146011?v=4)](https://github.com/chrissileinus "chrissileinus (20 commits)")

### Embed Badge

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

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

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