Documentation for SKOR PHP Template

Prerequisites

  • A webserver e.g.  Apache and PHP 5
  • PHP support for output buffering  (Output Buffering)
  • Skor template class
  • Skor section class (optional)

Installation

Download the classes here: unpack them  and put the files into your include directory.

Change the ownership and rights of the files the way it suits your requirements.

First steps

Create a textfile with the following content and save it as "template.tpl".

<html>
<body>
<h1>I call out: {UNIVERSE}</h1>
</body>
</html>

The "{UNIVERSE}" will be your placeholder for later replacement.

Now .create another file called test.php.

<?php
require_once('class_template.php');
$tpl = new template();
$tpl ->dir = '';
$tpl->html = 'template.tpl';
$tpl->read();
$tpl->assign('UNIVERSE', 'Hallo World');
$tpl->display();
?>

The "$tpl->dir" should point to the directory where you saved the template.tpl file in.
It must have a trailing slash ( / ),

"$tpl->html" already points to your template file. Of course it must be readable.

"$tpl->read()" will parse the template file now.

finally "$tpl->assign()" will do the replacement and "$tpl->display()" will show you the result.

Sections

The following is a somewhat more complex example to be used with class section:

<!--section-start::SITE-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="{LANG}" xml:lang="{LANG}">
<head>
<meta http-equiv="Content-Type" content="text/html; charset={CHARSET}" />
<title>{TITLE}</title>
<style type="text/css">
<!--
body {font-family: Arial, sans-serif; font-size:100.01%}
table.noborder {border:none; border-collapse:collapse;}
table.noborder tr.row_even td {background-color:#DDD; border-top: 1px solid #999; border-bottom: 1px solid #999;}
table.noborder td {padding:2px 10px 2px 3px;}
table.noborder td.first {font-weight:bold;}
-->
</style>
</head>
<body>
<h1>{HEADER}</h1>
<p>{INTRO}</p>
{S_TABLE}
</body>
</html>
<!--section-end::SITE-->

<!--section-start::TABLE-->
<table class="noborder">
{S_TABLE_ROW}
</table>
<!--section-end::TABLE-->

<!--section-start::TABLE_ROW-->
<tr class="row_{ODD}">
<td class="first">{POSITION}</td><td>{VORNAME} {NAME}</td><td>{TEL}</td>
</tr>
<!--section-end::TABLE_ROW-->

 

And the PHP-part:

<?php
require_once('class_template.php');
require_once('class_section.php');

$data = array ();
$data[] = array('vorname'=>'Franz','name'=>'Gumper','position'=>'Vorstand', 'tel'=>'05511 123 456-789');
$data[] = array('vorname'=>'Georg','name'=>'Bumpel','position'=>'Vorstand', 'tel'=>'03311 123 456-789');
$data[] = array('vorname'=>'Hans','name'=>'Hauer','position'=>'Vorstand', 'tel'=>'01155 123 456-789');

$tpl = new section();
$tpl ->dir = '';
$tpl->html = 'section.tpl';
$tpl->read();
$tpl->assign('LANG', 'de');
$tpl->assign('CHARSET', 'iso-8859-1');
$tpl->assign('TITLE', 'Test site: Section Test');
$tpl->assign('HEADER', 'Section Test');
$tpl->assign('INTRO', 'Just a little intro text ...');
$tmp = '';
for ( $i = 0; $i<sizeof($data); $i++) {
        $tpl->assign('POSITION', $data[$i]['position']);
        $tpl->assign('VORNAME', $data[$i]['vorname']);
        $tpl->assign('NAME', $data[$i]['name']);
        $tpl->assign('TEL', $data[$i]['tel']);
        $tpl->assign('ODD', (($i+1) % 2) ? 'odd' : 'even' );
        $tmp .= $tpl->fetch('TABLE_ROW');
}

$tpl->assign('S_TABLE_ROW', $tmp);
$tpl->assign('S_TABLE', $tpl->fetch('TABLE'));
$tpl->assign_section('SITE');
?>