PHPackages                             sluz/sluz - 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. sluz/sluz

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

sluz/sluz
=========

Sluz is a minimalistic PHP templating engine with an emphasis on syntax similar to Smarty.

v0.9.4(1mo ago)2181GPL-3.0-or-laterPHPPHP &gt;=8.0

Since May 4Pushed 4w ago2 watchersCompare

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

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

📰 Sluz PHP templating system
============================

[](#-sluz-php-templating-system)

Sluz is a minimalistic PHP templating engine with an emphasis on syntax similar to [Smarty](https://www.smarty.net/). This allows you to separate your logic (`.php`) and your presentation (`.stpl`) files.

The goal of Sluz is to be a **small**, single PHP source file, that emulates simple Smarty-like syntax.

📦 Getting started
-----------------

[](#-getting-started)

File: `script.php`

```
include('/path/to/sluz/sluz.class.php');
$s = new sluz();

$s->assign("name", "Jason");
$s->assign("version", "0.3");

print $s->fetch("tpls/script.stpl");
```

File: `tpls/script.stpl`

```
Hello {$name}

Welcome to Sluz version: {$version}

```

🧩 Template syntax
-----------------

[](#-template-syntax)

SyntaxExampleOutput`{$var}``{$name}``Jason``{$hash.key}` / `{$array.0}``{$cust.first}``Scott``{$var|modifier}``{$animal|strtoupper}``KITTEN``{$var|mod:params}``{$greet|substr:0,3}``Hel``{$var|mod1|mod2}``{$word|strtolower|ucfirst}``Crazy``{$var|default:"val"}``{$null|default:"?"}``?``{$var|escape}``{$name|escape}``&lt;script&gt;``{$expr}``{$number + 3}``18``{if}…{elseif}…{else}…{/if}``{if $x}yes{else}no{/if}``yes``{foreach $a as $v}``{foreach $items as $x}{$x}{/foreach}``onetwothree``{foreach $a as $k => $v}``{foreach $m as $idx => $z}{$idx}{/foreach}``012``$__FOREACH_FIRST/LAST/INDEX``{if $__FOREACH_FIRST}…{/if}`—`{include file='...'}``{include file='header.stpl'}`—`{literal}…{/literal}``{literal}function foo() { {/literal}``function foo() { ``{* comment *}``{* hidden *}`*(empty)*`{function()}``{count($array)}``3`🏷️ Alternate Delimiters
-----------------------

[](#️-alternate-delimiters)

By default Sluz uses `{` and `}` as delimiters. If your content frequently contains braces (e.g. CSS, JSON, JavaScript), you can switch to a different single-character pair:

```
$s->set_delimiters('[', ']');
```

With the above, all template tags use `[` and `]`:

```
[{$name}]
[if $admin]Hello admin[/if]
[foreach $items as $item][/foreach]
[* this is a comment *]
[literal]{$name} is not parsed[/literal]

```

**Constraints:** Both delimiters must be single characters and must not be the same character.

🔒 Security
----------

[](#-security)

Template variables hold untrusted data (form input, database rows, URL parameters) by default. The `{$var}` construct emits the value verbatim, so a template that renders user data without escaping is vulnerable to cross-site scripting (XSS).

Always use the `escape` modifier on untrusted output:

```
{$user_input|escape}          {* HTML-encode (default) *}
{$redirect_url|escape:"url"}  {* URL-encode *}
{$inline_js|escape:"js"}      {* JavaScript-string-encode *}

```

By default `escape` uses PHP's `htmlspecialchars()` with `ENT_QUOTES | ENT_SUBSTITUTE` and UTF-8 encoding, which converts ``, `"`, and `'` to their HTML entity equivalents.

### 🛡️ Auto-escape

[](#️-auto-escape)

For stricter safety you can enable automatic HTML escaping of all variable output. When enabled, every `{$var}` is escaped unless the template explicitly opts out with `|raw`.

```
$s->setEscapeHtml(true);
```

```
{$user_input}                {* auto-escaped *}
{$user_input|escape}         {* not double-escaped *}
{$user_input|escape:"url"}   {* URL-escaped, not overridden *}
{$trusted_html|raw}          {* opt-out: output verbatim *}

```

**Note:** Auto-escaping only applies to `{$var}` variable blocks. Expression blocks like `{$x + 3}` and function calls like `{count($array)}` are not auto-escaped.

🤵 Composer
----------

[](#-composer)

If you are a composer user you can install Sluz with this command:

```
composer require sluz/sluz

```

📐 Requirements
--------------

[](#-requirements)

Sluz requires PHP 8.0+, and is a zero-dependency library. **Only** the `sluz.class.php` file is needed for the library to function.

🥽 Testing
---------

[](#-testing)

Sluz has an extensive test suite that is used to verify compatibility across PHP versions. As of this writing Sluz passes all unit tests on PHP versions: 8.0, 8.1, 8.2, 8.3, 8.4, and 8.5.

To run the tests issue this command at the CLI:

```
php unit_tests/tests.php

```

**Note:** Care was taken to ensure that no `E_NOTICE` warnings are emitted and that Sluz is `error_reporting(E_ALL)` compliant.

📖 Documentation
---------------

[](#-documentation)

There is extensive documentation in the `docs/` with real world examples of the syntax.

🧬 See Also
----------

[](#-see-also)

- [Template::Sluz](https://github.com/scottchiefbaker/perl-Template-Sluz) / Perl
- [Template-Sluz](https://github.com/scottchiefbaker/js-Template-Sluz) / JavaScript

🔤 Naming
--------

[](#-naming)

Sluz is pronounced "slooz". The name comes from the "S" in Smarty and "luz" which is Spanish for light. Sluz is a lite, Smarty-like templating system.

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance94

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity32

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

Every ~25 days

Total

3

Last Release

31d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9abab1acc5a8df8723cc365fc7cbc437bb9844fd9f0b9d0a8950925b1ae2ff4d?d=identicon)[scottchiefbaker](/maintainers/scottchiefbaker)

---

Top Contributors

[![scottchiefbaker](https://avatars.githubusercontent.com/u/3429760?v=4)](https://github.com/scottchiefbaker "scottchiefbaker (457 commits)")

---

Tags

phptemplatetemplatingsmartyengine

### Embed Badge

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

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

###  Alternatives

[eftec/bladeone

The standalone version Blade Template Engine from Laravel in a single php file

8299.7M113](/packages/eftec-bladeone)

PHPackages © 2026

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