Добро пожаловать на форум PHP программистов!
За последние 24 часа нас посетили 159947 программистов и 7848 роботов. Сейчас ищут 3002 программиста ...

Simple example

Вернуться к: HTML_Template_PHPLIB

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(
    
'Christian Weiske'  => 'cweiske@php.net',
    
'Bjoern Schotte'     => 'schotte@mayflower.de'
);

require_once 
'HTML/Template/PHPLIB.php';
//create template object
$t =& new HTML_Template_PHPLIB(dirname(__FILE__), 'keep');
//load file
$t->setFile('authors', 'authors.tpl');
//set block
$t->setBlock('authors', 'authorline', 'authorline_ref');

//set some variables
$t->setVar('NUM_AUTHORS', count($authors));
$t->setVar('PAGE_TITLE', 'Code authors as of ' . date('Y-m-d'));

//display the authors
foreach ($authors as $name => $email) {
    
$t->setVar('AUTHOR_NAME', $name);
    
$t->setVar('AUTHOR_EMAIL', $email);
    
$t->parse('authorline_ref', 'authorline', true);
}

//finish and echo
echo $t->finish($t->parse('OUT', 'authors'));
?>


Вернуться к: HTML_Template_PHPLIB

© 2026 «PHP.RU — Сообщество PHP-Программистов»
Главная | Форум | Реклама на сайте | Контакты
Разработка компании ODWR