Terminal Icon

Stamps

» Stamp, alternative PHP Templates

Besides the paper model metaphor you can build output from templates using a slightly more rudimentary approach; to treat the template like a collection of stamps. The 'stamp' mode consists mostly of two functions: copy() - to copy a certain section in your template and replace() - to replace a portion of your template.

Consider the following template:

 

    
<ul class="tabs">
        <!-- 
tab -->
            <
li>
                <
class="#active#" href="#href#">#tab#</a>
            
</li>
        <!-- /
tab -->
    </
ul>

This is a template for a menu for a website using tabs. Now let's assume we have an array containing the menu items together with the content pages that have to be associated with the hyperlinks:

 
    $current 
"news";
    
$tabs = array("home.html"=>"homepage","news.html"=>"news","about.html"=>"about");

The template can be applied to the array using the following code:

 
    $s 
= new Stamp($template);
    
$menu "";
    foreach(
$tabs as $lnk=>$t)
        
$menu .= $s->copy("tab")->put("href",$lnk)->put("tab",$t)->put("active",($current==$t)?"active":"inactive");
    
    echo 
$s->replace("tab",$menu);

Manual Pages

  • Philosophy
  • Welcome
  • Basics
  • Download
  • Painter Plugins
  • Navigation
  •  



    copyright © 2011 Gabor de Mooij | Stamp PHP Template Library