Stamp Template Engine

The Stamp Template Engine is a string based, logic-less template engine. This means 100% separation between PHP, HTML and data. 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 of the lib!).

News

: StampTE 2.2 Beta 2 has been released! Help us test the new StampTE!
: StampTE 2.2 Beta 1 has been released! Help us test the new StampTE!

Get started!

This is how you make a pizza 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 pricelist from the template string. The resulting output would look like this:


PizzaPrice
Margherita7.00
Funghi7.50
Tonno8.00




How it works

You can already see how it works without reading about the details. 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.

Logic-less

It's Clean. No more PHP in your HTML. This means: toll free template upgrades. Templates no longer have to be converted to be used with PHP logic. Because templates do not have to be adjusted you can show the live templates to your customer in the browser. Templates become plug-and-play. This also makes it a lot easier to exchange templates.

No new syntax

Most template engineers already use HTML markers to mark regions. Stamp Template Engine uses these very same familiar markers for PHP logic. Templates become self-documenting and more readable.

Automatically escapes strings for unicode (X)HTML documents. No more HTML injections! Unit tested. Cleans comment markers afterwards.

Download

Download the latest version of Stamp Template Engine.

Stamp TE is licensed new BSD. Download Stamp TE v 2.2 Beta
Download Stamp TE v 2.1.6