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

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

spreadable/template
===================

A composition-oriented template engine, written in PHP.

1.5.4(4y ago)17MITPHPPHP &gt;=8.0

Since Oct 18Pushed 4y ago1 watchersCompare

[ Source](https://github.com/spreadable/template)[ Packagist](https://packagist.org/packages/spreadable/template)[ Docs](https://github.com/spreadable/template)[ RSS](/packages/spreadable-template/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (10)DependenciesVersions (13)Used By (0)

spreadable/template
===================

[](#spreadabletemplate)

A composition-oriented template engine, written in PHP.

Install
-------

[](#install)

`composer install spreadable/template`

The markers
-----------

[](#the-markers)

There is 2 types of markers:

- `{user.name}`: a marker for **required** data
- `{?user.name}`: a marker for **optional** data

Special meaning of a unique optional marker on an attribute
-----------------------------------------------------------

[](#special-meaning-of-a-unique-optional-marker-on-an-attribute)

An attribute contains a unique optional marker and if the provided value is `null`, on the rendering, that attribute is simply removed, useful for boolean attributes.

Basic templates
---------------

[](#basic-templates)

```
use function Spreadable\Template\fragment;

/*
{salutations} {user}
*/
$paragraph = fragment('./paragraph.html');

/*
{name}
*/
$user = fragment('./user.html');

$visitor_paragraph = $paragraph([
    'salutations' => 'Hello',
    'user' => 'visitor'
]);

$jane_paragraph = $visitor_paragraph([
    'class' => 'woman',
    'user' => $user([
        'name' => 'Jane'
    ])
]);

$john_paragraph = $visitor_paragraph([
    'class' => 'man',
    'user' => $user([
        'name' => 'John'
    ])
]);

var_dump([
    'visitor' => $visitor_paragraph->serialize(), // Hello visitor
    'jane' => $jane_paragraph->serialize(), // Hello Jane"
    'john' => $john_paragraph->serialize() // Hello John
]);
```

Build an entire page
--------------------

[](#build-an-entire-page)

```
// Additionally, to the previous code
use function Spreadable\Template\page;

/*

*/
$head_fragment = fragment('./head-fragment.html');

/*
Branding Name

  Page title
  {contents}

*/
$body_fragment = fragment('./body-fragment.html');

$page = page(
    'en',
    'Branding Name',
    $head_fragment([
        'timestamp' => time()
    ]),
    $body_fragment([
        'contents' => [
            $visitor_paragraph,
            $jane_paragraph,
            $john_paragraph
        ]
    ])
);

echo $page->serialize();
/*

    Page title - Branding Name

    Branding Name

      Page title
      Hello visitor
      Hello Jane
      Hello John

*/
```

Prefilling
----------

[](#prefilling)

*Added in **1.1.0***

Sometimes, it can be interesting to prefill some **fragments** to avoid making the entire filling job during the runtime.

For that reason, you can call `$fragment->serialize(string $prefix = null)` with a **prefix** matching the first marker segment.

You can now save them as files to be able to reuse them to only fill the rest during the runtime.

Mapping
-------

[](#mapping)

*Added in **1.2.0***

A fragment has a `$fragment->map(array $datas, callable $callback = null)` which calls the fragment on each entry.

Instead, if a `$callback` is provided, the fragment is called on the result of `$callback($datas_entry_value, $datas_entry_key, $datas)`

License
-------

[](#license)

[MIT](./license)

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

Established project with proven stability

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

Total

12

Last Release

1697d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9c778b83e9c4f315ba0802eb07a6867b5a6aa84c93c73ad334da45568881466e?d=identicon)[Lcf.vs](/maintainers/Lcf.vs)

---

Top Contributors

[![Lcfvs](https://avatars.githubusercontent.com/u/2665124?v=4)](https://github.com/Lcfvs "Lcfvs (16 commits)")

### Embed Badge

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

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

###  Alternatives

[limenius/react-bundle

Client and Server-side react rendering in a Symfony Bundle

3851.2M](/packages/limenius-react-bundle)[area17/laravel-auto-head-tags

Laravel Auto Head Tags helps you build the list of head elements for your app

4616.1k](/packages/area17-laravel-auto-head-tags)[jelix/wikirenderer

WikiRenderer is a library to generate HTML or anything else from wiki content.

1712.3k1](/packages/jelix-wikirenderer)[webkinder/sproutset

A Composer package for handling responsive images in Roots Bedrock + Sage + Blade projects.

282.2k](/packages/webkinder-sproutset)

PHPackages © 2026

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