written: Sep 1 2007
Template Variable
Template variable is enclosed with the begin tag {?= and end tag ?}. Template variable to be replace is written like this. {?=$TEMPO_VAR?}.
[code html;gutter:false]
<p>[[[ {?=$TEMPO_VAR?} ]]]</p>
[/code]
< Template file : tempo.sample.htm >
[code php;gutter:false]
<?php
require_once('class.Tempo.php');
$tempo = new Tempo;
$tempo->parse('sample', 'tempo.sample.htm');
$TEMPO_VAR = 'The value assigned by PHP global variable';
print $sample->assign();
$tempo->close($sample);
?>
[/code]
< PHP coding >
[code html;gutter:false]
<p>[[[ The value assigned by PHP global variable ]]]</p>
[/code]
< Result >
BLOCK element
BLOCK allows you to set dynamic content within a static template. The notation of the block element of TEMPO and the Zope ZPT is similar. Well, with tempo you now can write :
[code html;gutter:false]
<table>
<tr>
<th>classify</th>
<th>column1</th>
<th>column2</th>
<th>column3</th>
</tr>
<tr tempo:id="eLoop">
<td>{?=$this->column0?}</td>
<td>{?=$this->column1?}</td>
<td>{?=$eLoop->column2?}</td>
<td>{?=$eLoop->column3?}</td>
</tr>
</table>
[/code]
< Template contents >
TEMPO attribute statements
These are the TEMPO attribute statements:
- tempo:id - block handle. it is a unique identifier.
- tempo:omit - remove tag, contents or block.
- tempo:ctype - set contents type(text, html, php or not).
Tag attribute statement has a name and its value.
tempo:id statement
The block element on which a statement is defined is a unique identifier in the current HTML document. For example,
tempo:id="eLoop"
tempo:omit statement
remove tag, contents or block.
[code html;gutter:false]
<html tempo:omit="tag">
<head tempo:omit="block">
<title tempo:id="docTitle" tempo:omit="tag">Template file open</title>
</head>
<body tempo:omit="tag">
<p><?php print $docTitle->outerHTML; ?></p>
<p>Welcome to tempo.phpclass.com!</p>
<p tempo:omit="content">(oct 3, 2007)</p>
</body>
</html>
[/code]
< Template contents : tempo.sample.htm >
[code php;gutter:false]
<?php
require_once('class.Tempo.php');
$tempo = new Tempo;
$tempo->parse('sample', 'tempo.sample.htm');
print $sample->assign();
$tempo->close($sample);
?>
[/code]
< PHP coding >
[code html;gutter:false]
<p>Template file open</p>
<p>Welcome to tempo.phpclass.com!</p>
<p></p>
[/code]
< Result(code) >
tempo:ctype statement
[code php;gutter:false]
<table border=1>
<tr>
<th>ctype</th><th>result</th>
</tr>
<tr>
<td>default</td><td><div><span style="color:red;"><?=$VAR?></span></div></td>
</tr>
<tr>
<td>text</td><td><div tempo:ctype="text"><span style="color:red;"><?=$VAR?></span></div></td>v </tr>
<tr>
<td>html</td><td><div tempo:ctype="html"><span style="color:red;"><?=$VAR?></span></div></td>
</tr>
<tr>
<td>php</td><td><div tempo:ctype="php"><span style="color:red;"><?=$VAR?></span></div></td>
</tr>
</table>
[/code]
< Template contents : tempo.sample.htm >
[code php;gutter:false]
<?php
require_once('class.Tempo.php');
$tempo = new Tempo;
$tempo->parse('sample', 'tempo.sample.htm');
$VAR = 'apple';
print $sample->assign();
$tempo->close($sample);
?>
[/code]
< PHP coding >
ctype | result |
---|---|
default |
apple
|
text | <span style="color:red;"><?=$VAR?></span> |
html | <?=$VAR?> |
php | <span style="color:red;">apple</span> |
tempo:include statement
You can specify which file to include in template file. (Like header.html and footer.html).
[code php;gutter:false]
[[[ {?=$TEMPO_VAR?} ]]]
[/code]
< Template file : tempo.sub.htm >
[code html;gutter:false]
<p tempo:include="tempo.sub.htm"></p>
[/code]
< Template file : tempo.main.htm >
[code php;gutter:false]
<?php
require_once('class.Tempo.php');
$tempo = new Tempo;
$tempo->parse('eRoot', 'tempo.main.htm');
$TEMPO_VAR = "The value assigned by PHP global variable";
print $eRoot->assign();
$tempo->close('eRoot');
?>
[/code]
< PHP coding >
[code html;gutter:false]
<p>[[[ The value assigned by PHP global variable ]]]</p>
[/code]
< Result >
Auto adjust path
Tempo will automatically adjust HTML resource(image, link etc) path.
'phpsource > 템플릿' 카테고리의 다른 글
{Tempo}5.Example - Repeat Block (0) | 2007.09.01 |
---|---|
{Tempo}4.Class Methods (0) | 2007.09.01 |
{Tempo}2.Step by step (0) | 2007.09.01 |
{Tempo}1.Introduction (0) | 2007.09.01 |
{후키템플릿}9.5.게시판 목록보기 구현 (0) | 2006.11.03 |