Welcome to Sluz v0.9.4

What is Sluz?

Sluz is a minimalistic PHP templating engine with an emphasis on syntax similar to Smarty. 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 template syntax.

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.

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.

Getting started:
File: script.php
include('/path/to/sluz/sluz.class.php');
$s = new sluz();

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

print $s->fetch("tpls/script.stpl");
File: tpls/script.stpl
<h1>Hello {$name}</h1>

<div>Welcome to Sluz version: {$version}</div>
Template Syntax:
Syntax Example Output
{$var}{$name}Jason
{$hash.key} / {$array.0}{$cust.first}Scott
{$var|modifier}{$animal|strtoupper}KITTEN
{$var|mod:params}{$greet|substr:0,3}Hel
{$var|m1|m2}{$word|strtolower|ucfirst}Crazy
{$var|default:"val"}{$null|default:"?"}?
{$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 $k=>$v}{$k}{/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
More documentation
Run unit tests