Examples

Here are a couple of examples to demonstrate the usage of StampTE.

Basic HTML5 Document

Here is how you can use the createHTML5Utf8Document() method to create a simple HTML5 skeleton document for you:

    $tpl StampTE::createHtml5Utf8Document();

    
$tpl->setTitle('Welcome to StampTE');

    
$tpl->add($tpl
            
->getLink()
            ->
copy()
            ->
setRel('stylesheet')
            ->
setType('text/css')
            ->
setHref('style.css'));


    
$tpl->add($tpl
            
->getScript()
            ->
copy()
            ->
setSrc('js/script.js'));

    
$myTemplateStr '<span>#greeting#</span>';
    
$myTemplate = new StampTE$myTemplateStr );
    
$myTemplate->setGreeting'Hello World!' );
    
$tpl->body->add$myTemplate );

    echo 
$tpl;

Forms

This is how you can build a form using StampTE:

    <form action="#action#" method="post">
    <!-- 
cut:textField -->
    <
label>
        
#label#
    
</label>
    <
input type="text" name="#name#" value="#value#" />
    <!-- /
cut:textField -->
    </
form>

PHP code:

    $form = new StampTE($t);
    
$form->setAction('/action');
    
$textField $form->getTextField();
    
$textField->setLabel('Your Name')
        ->
setName('person')
        ->
setValue('It\'s me!');
    
$form->add($textField);

Note that we do not need to specify the glue point when adding the textfield to the form. StampTE is smart enough to know that it should be pasted on the original location, where the cut point marker had been placed.
So, there is no need to add a glue point marker after the cut point marker 'textfield', it does not cause problems however if you also add the glue point marker. It's just a convenience feature.
Result:

    <form action="#action#" method="post">
        <
label>Your Name</label>
        <
input type="text" name="person" value="It's me!" />
    </
form>

Games

Here is an example how you can use StampTE for a slightly more complex view, for instance as part of a game. In strategy games you are likely to have views that contain many different pieces (armies, villages etc). StampTE is especially suited for this kind of view because you can treat all the individual elements in the view as objects:

    $vt '<div id="forest">
        <div id="village">
        <!-- paste:village -->
        </div></div>'
;
    
$bt '
        <div class="catalogue">
        <!-- cut:tavern -->
            <img src="tavern.gif" />
        <!-- /cut:tavern -->
        </div>
    '
;

    
$v = new StampTE($vt);
    
$b = new StampTE($bt);
    
$tavern $b->getTavern();
    
$v->village->add($tavern);

Integration: Bricks

You can use StampTE together with other template engines like Smarty, Zend View or Twig. In StampTE these templates are considered dirty because they contain logic mixed with HTML. These templates are therefore called bricks (because they cannot be changed by the design team). However bricks can be integrated into StampTE to speed up performance or to keep backward compatibility with legacy code bases. StampTE does not offer special features to interact with these so-called bricks, however integration is fairly straight forward:

    $view = new MyUglyViewSystem();
    
$output $view->render();
    
$snippet = new StampTE($output);
    
$beautiful->glue('justabrick',$snippet);

Because the StampTE constructor accepts strings you can simply pass the output from another template engine or view system to StampTE and it becomes usable. Note that you can still inject variables in slot markers and you can still use markers after importing output strings from other template engines. Also, like all other Stamp Snippets HTML comments will be removed.