PHPackages                             dhii/delimited-token-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. dhii/delimited-token-template

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

dhii/delimited-token-template
=============================

A flexible implementation for handlebars-style templates

v0.1.0(5y ago)036.0kMITPHPPHP ^7.0CI failing

Since Mar 4Pushed 5y ago2 watchersCompare

[ Source](https://github.com/Dhii/delimited-token-template)[ Packagist](https://packagist.org/packages/dhii/delimited-token-template)[ RSS](/packages/dhii-delimited-token-template/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (3)Dependencies (3)Versions (5)Used By (0)

Delimited Token Template
========================

[](#delimited-token-template)

A flexible implementation for handlebars-style templates.

[![Continuous Integration](https://github.com/Dhii/delimited-token-template/actions/workflows/continuous-integration.yml/badge.svg)](https://github.com/Dhii/delimited-token-template/actions/workflows/continuous-integration.yml)[![Latest Stable Version](https://camo.githubusercontent.com/c4a4be468cba1a43ca13ebbaec52a83e434b4656ad5abf1fc459fc5a8f2307e3/68747470733a2f2f706f7365722e707567782e6f72672f646869692f64656c696d697465642d746f6b656e2d74656d706c6174652f76)](//packagist.org/packages/dhii/delimited-token-template)[![Latest Unstable Version](https://camo.githubusercontent.com/fa1c9bb24a4945ff4eb6bf9a76b33d6d7e26895234deb6c9b58ebc5795e5d289/68747470733a2f2f706f7365722e707567782e6f72672f646869692f64656c696d697465642d746f6b656e2d74656d706c6174652f762f756e737461626c65)](//packagist.org/packages/dhii/delimited-token-template)

Details
-------

[](#details)

This template implementation is useful if you need to replace simple tokens with values. Good examples are emails, which contain text like "Hello, %username%", or paths with variable segments, such as "/users/:username/profile".

The template supports any string delimiters: '\[\*placeholder\*\]', '~placeholder', and "{{placeholder}}" will all work. It's possible to have the left delimiter different from the right one, have delimiters which contain more than one character, or to even omit *one* of the delimiters.

When two delimiters are used, they can be escaped by a configurable escape character to make them be used literally in the rendered result. With the left and right delimiters being "{{" and "}}" respectively, and the escape char being "", the string "{{ {{username}}" could produce "{{ johnny" if rendered with context `['username' => 'johnny']`. If the second left delimiter was escaped instead, i.e. "Hello, {{ {{username}}", rendering with `[' {{username' => 'johnny']` would produce "Hello, johnny". This demonstrates that escaped delimiters will be replaced with their literal value in both the end result, and in token names.

Using one delimiter is also possible, e.g. "Hello, :username!" would produce "Hello, johnny!" when rendered with context `['username' => 'johnny']`. In this case, however, contrary to using two delimiters, token names are limited to alphanumeric chars, as well as '\_', '-', and '.' (underscore, dash, and period). In addition, it is not possible to escape delimiters. Consequently, token names cannot contain delimiters.

### Usage

[](#usage)

#### Two delimiters

[](#two-delimiters)

This example uses two identical delimiters, and an escaped delimiter in the middle of the token name.

```
use Dhii\Output\DelimitedTokenTemplate\Template;

$template = new Template('Hello, %user\%name%!', '%', '%', '\\'); // Note escaped delimiter
$template->render(['user%name' => 'johnny']); // Hello, johnny!
```

#### Different long delimiters

[](#different-long-delimiters)

This example uses two different delimiters that are longer than 1 character, and of different lengths.

```
use Dhii\Output\DelimitedTokenTemplate\Template;

$template = new Template('Hello, -user\-name__!', '-', '__', '\\'); // Note completely different delimiters
$template->render(['user-name' => 'johnny']); // Hello, johnny!
```

#### One delimiter with factory

[](#one-delimiter-with-factory)

Often times there will be some kind of convention within your application with regard to delimiters and the escape character. This these cases, it often useful to be able to instantiate several templates based on that standard, without having to specify it every time. The factory can represent that convention. This example uses tokens with only the left delimiter.

```
use Dhii\Output\DelimitedTokenTemplate\TemplateFactory;

$factory= new TemplateFactory(':', '', ''); // Note absence of right delimiter and escape character
$profilePath = $factory->fromString('/users/:username/profile')
    ->render(['username' => 'johnny']); // '/users/johnny/profile'
$settingsPath = $factory->fromString('/users/:userId/settings')
    ->render(['userId' => '1234']); // '/users/1234/settings'
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity44

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

Total

3

Last Release

1903d ago

PHP version history (2 changes)v0.1.0PHP ^7.0

v0.2.0-alpha1PHP ^7.1 | ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/1894e91b32c9f80d8f30a42d360af6983a507f1cf2c621b7c9a0a0de14e011c5?d=identicon)[XedinUnknown](/maintainers/XedinUnknown)

---

Top Contributors

[![XedinUnknown](https://avatars.githubusercontent.com/u/1428973?v=4)](https://github.com/XedinUnknown "XedinUnknown (44 commits)")

---

Tags

standards-comptemplate

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dhii-delimited-token-template/health.svg)

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

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