Stamp Template Engine

The Stamp Template Engine is a string based, logic-less template engine. This means 100% separation between PHP and HTML.
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.1 has been released, performance improvement.
: Updating documentation
: StampTE 2.2 has been released!

Get started!

Let's begin with a practical example. 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.

Logic-less

It's Clean. No more PHP in your HTML.
This also means: toll free template upgrades. Templates no longer have to be converted (insert PHP tags etc...) so you can simply swap files to upgrade your design.
Because templates do not have to be converted anymore 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.
Finally this approach makes it easy for different teams to work together (design team and development team).

No new syntax

Most competent designers and 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.

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

Download

Download the latest version of Stamp Template Engine.

Stamp TE is licensed new BSD. Download Stamp TE v 2.2.1