Stamp T|E

Stamp Template Engine

The Stamp Template Engine is a string based, logic-less template engine. This means 100% separation between PHP and HTML. Stamp is often used for complex server rendered views.

Working with StampTE is like playing with a paper model, cut out parts and glue them together (a Stamp is also an appropriate metaphor, hence the name).

News

: Released version 2.3.4
: Added privacy statement
: Released version 2.3.2
: Released version 2.3.1
: Released version 2.3
: Released version 2.2.2
: Migrated to new server.
: StampTE 2.2.1 has been released, performance improvement.
: Updating documentation
: StampTE 2.2 has been released!

Why use Stamp?

  • Toll free template upgrades (because no logic in template)
  • Hot-swappable templates
  • 3rd party templates
  • Show live demo templates to your customer (demojs)
  • Fully independent design team (and development team)
  • Programmable templates (complex views and forms)
  • Built-in XSS filter and UTF-8 encoding
  • Integrate translation functions
  • No new syntax, leverages well known comment conventions
  • self-documenting templates

Don't use StampTE for: very simple templates, APIs or non-UTF-8 templates.

Changelog

2.3.4: Added inconv UTF-8 encoder and load html5document from library folder.
2.3.1: Added u modifier for better UTF-8 support in regular expression.
2.3.0: UTF-8 support, PHP 7 compatibility, improved HTML5 document template.

Get started!

This is how you make a price list for an Italian restaurant using StampTE:

Template:


<table>
    <
thead>
        <
tr><th>Pizza</th><th>Price</th></tr>
    </
thead>
    <
tbody>
    <!-- 
cut:pizza -->
        <
tr><td>
        
#name#
        
</td><td>
        
#price#
        
</td></tr>
    <!-- /
cut:pizza -->
    </
tbody>
</
table>

Let's add some data:


$data 
= array(
'Margherita' => '7.00',
'Funghi' => '7.50',
'Tonno' => '8.00'
);

The PHP logic:


$htmlDocument 
StampTE::createHtml5Utf8Document();
$htmlDocument->setTitle('Pizza');

$priceList = new StampTE($template);
foreach(
$data as $name=>$price) {
    
$pizza $priceList->getPizza();
    
$pizza->setName($name);
    
$pizza->setPrice($price);
    
$priceList->add($pizza);
}

$htmlDocument->body->add($priceList);

The resulting HTML:


<!DOCTYPE html>
<
html>
<
head>
<
meta charset="UTF-8">
<
title>Pizza</title>
</
head>
<
body>
    <
table>
    <
thead><tr><th>Pizza</th><th>Price</th></tr></thead>
    <
tbody>
    <
tr><td>Magaritha</td><td>7.00</td></tr>
    <
tr><td>Funghi</td><td>7.50</td></tr>
    <
tr><td>Tonno</td><td>8.00</td></tr>
    </
tbody>
    </
table>
</
body>
</
html>

As you can see in the HTML output above the createHtml5Utf8Document() convenience method creates a valid HTML5 document skeleton for you. We then create a price list from the template string. The resulting output looks like this:


PizzaPrice
Margherita7.00
Funghi7.50
Tonno8.00


How it works

It's easy to see how this template engine works by just reading the example. StampTE simply converts the regions marked in the template to objects you can manipulate. It cuts out the regions and you can then reshuffle them in your HTML.

No new syntax

Stamp uses markers, HTML comments. These markers are used to identify regions in the HTML template. Most template engineers already use such markers for readability. Templates become self-documenting and more readable.

StampTE Automatically escapes strings for unicode (X)HTML documents. So no longer have to worry about XSS!