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

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

dalpras/smart-template
======================

Smart template engine for key-value substitutions

v4.4.1(4w ago)2151proprietaryPHPPHP &gt;=8.3

Since Oct 9Pushed 4w ago1 watchersCompare

[ Source](https://github.com/dalpras/smart-template)[ Packagist](https://packagist.org/packages/dalpras/smart-template)[ RSS](/packages/dalpras-smart-template/feed)WikiDiscussions main Synced yesterday

READMEChangelog (4)Dependencies (6)Versions (25)Used By (1)

Smart Template
==============

[](#smart-template)

A small PHP template engine for structured rendering with native PHP arrays, lazy compilation, presets, and named placeholder substitution.

`smart-template` is designed for projects that want to keep rendering logic in PHP without introducing a separate template language.

Templates are regular PHP arrays made of strings, callbacks, and nested arrays. String leaves are lazily compiled into render closures when accessed.

---

What it is good at
------------------

[](#what-it-is-good-at)

- Small, reusable HTML fragments and components
- PHP-native template composition
- Dynamic rendering with named placeholders
- Preset-based template registration
- In-memory template collections
- Fine-grained control over escaping and HTML attributes
- Exact custom parameter callbacks
- Call-site token modifiers
- Configurable modifier separator

What it is not
--------------

[](#what-it-is-not)

This package is **not** a full view framework.

It does not try to replace systems built around inheritance, blocks, macros, filters, or expression languages.

It works best when you want explicit PHP control over markup and composition.

---

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

[](#installation)

```
composer require dalpras/smart-template
```

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

[](#requirements)

- PHP 8.3 or newer

---

Mental model
------------

[](#mental-model)

A template collection is an array registered under a namespace.

Each entry can be:

- a **string** with placeholders such as `{title}` or `{rows}`
- a **closure**
- a **nested array** of more templates
- a lazy template-file reference

When a string leaf is accessed, the engine compiles it lazily into a closure.

Example:

```
echo $template['card']([
    '{title}' => 'Hello',
    '{body}' => 'Welcome',
]);
```

If a placeholder value is itself a closure, the engine resolves it before substitution.

---

Quick start
===========

[](#quick-start)

1) Create a preset
------------------

[](#1-create-a-preset)

```
