Template file: authors.tpl
<html> <head><title>{PAGE_TITLE}</title></head> <body> <table> <caption>Authors</caption> <thead> <tr><th>Name</th><th>Email</th></tr> </thead> <tfoot> <tr><td colspan="2">{NUM_AUTHORS}</td></tr> </tfoot> <tbody> <!-- BEGIN authorline --> <tr><td>{AUTHOR_NAME}</td><td>{AUTHOR_EMAIL}</td></tr> <!-- END authorline --> </tbody> </table> </body> </html> |
PHP code: authors.php
<?php //we want to display this author list $authors = array( 'Author 1' => 'author1@php.net', 'Author 2' => 'author2@yahoo.com' ); //load file $tpl->setFile('tpl_authors', 'authors.tpl'); //set block $tpl->setBlock('tpl_authors', 'authorline', 'authorline_block'); //set some variables $tpl->setVar('NUM_AUTHORS', count($authors)); $tpl->setVar('PAGE_TITLE', 'Code authors as of ' . date('Y-m-d')); //display the authors foreach ($authors as $name => $email) { $tpl->setVar('AUTHOR_NAME', $name); $tpl->setVar('AUTHOR_EMAIL', $email); $tpl->parse('authorline_block', 'authorline', true); } // parse and print the output $tpl->pparse('OUTPUT', 'tpl_authors'); ?> |