phpsource/템플릿2007. 9. 1. 17:35
written: Sep 1 2007
Classify of class methods
The implemented methods are:
# Whole template contents
  • Tempo()
  • parse(string $template_handle, string $template_file)
  • parse_str(string $template_handle, string $template_string)
  • clear(string $template_handle)
# BLOCK element
  • assign([array $loop_data])
  • loop(string $name)
  • attribute(string $name [, string $value])
  • style(string $name [, string $value])
  • tempo(string $name [, string $value])
Class methods of whole template contents
[code php;gutter:false] <?php require_once('class.Tempo.php'); $tempo = new Tempo; $tempo->parse('eRoot', 'templates/tempo.sample.htm'); . . . $tempo->clear('eRoot'); ?> [/code]
< Process of whole template contents >
Tempo()
Tempo() creates a new template object. Called via new, returns a newly allocated template object.
[code php;gutter:false] $tempo = new Tempo; [/code]
parse(string $template_handle, string $template_filename)
Parse the template contents(file). First parameter is the template handle corresponding the template contents to be processed. Second parameter is the template filename. When the file is loaded, it is parsed.
[code php;gutter:false] $tempo->parse('eRoot', 'templates/tempo.sample.htm'); [/code]
parse_str(string $template_handle, string $template_string)
Parse the template contents(string). First parameter is the template handle corresponding the template contents to be processed. Second parameter is the template string to be parsed.
[code php;gutter:false] $tempo->parse_str('eRoot', '

[[[ <?=$TEMPO_VAR?> ]]]

'); [/code]
for example:
[code php;gutter:false] <?php require_once('class.Tempo.php'); $tempo = new Tempo; $tempo->parse('eRoot', '

[[[ <$TEMPO_VAR/> ]]]

'); [/code]
< PHP coding >
clear(string $template_handle)
clear() clear the parsed contents. Using method close() isn't usually necessary, the parsed contents is automatically cleared at the end of the script's execution.
[code php;gutter:false] $tempo->clear('eRoot'); [/code]
Class methods of BLOCK element
assign([array $loop_data])
This method inserts the values of all the variables that assigned the PHP global variables into the template. It will return the template contents that has been set variables. The returned value is able to be printed to STDOUT via print or echo.
[code php;gutter:false] $tempo->parse('eRoot', $template_contents); print $eRoot->assign(); [/code]
< PHP coding >
First parameter of assign() is the data in the array for loop block. This method takes an array (which has to be in the format described below) and automatically substitutes the variables of a loop block(ex:table row) in template contents for the loop data.
[code php;gutter:false] $column[0]['column0'] = 'Country'; $column[0]['column1'] = 'Korea'; $column[0]['column2'] = 'USA'; $column[0]['column3'] = 'Germany'; $column[1]['column0'] = 'Capital city'; $column[1]['column1'] = 'Seoul'; $column[1]['column2'] = 'Washington DC'; $column[1]['column3'] = 'Berlin'; $column[2]['column0'] = 'Population'; $column[2]['column1'] = '49,000,000'; $column[2]['column2'] = '301,000,000'; $column[2]['column3'] = '82,000,000'; 1st index is the row number of loop, starting at zero. 2nd index is the column name of loop. [/code]
The detailed usage for loop data refers to the 'Example - Repeat Block' section.
loop(string $name)
For each loop, the local variable is set to the current loop data. You use loop local variables to access information about the current loop (such as the loop index). The loop local variables is only accessible through the built-in member loop().
index - loop index, starting from zero.
data - current loop data.
groups - the number of group.
rows - the number of row.
fields - the number of field.
For example,
[code html;gutter:false] <div> the number of record: {?=$eLoop>loop('rows')?}<br /> the number of field: {?=$eLoop->loop('fields')?} </div> <table border="1"> <tr style="height:30;"> <th bgcolor="#000066" style="color:white;">classify</th> <th bgcolor="#0000dd" style="color:white;">column1</th> <th bgcolor="#0000dd" style="color:white;">column2</th> <th bgcolor="#0000dd" style="color:white;">column3</th> </tr> <tr tempo:id="eLoop" bgcolor="silver" style="height:30;"> <td bgcolor="#000066" style="color:white;"> {?=$eLoop->loop('index')?}.{?=$eLoop->column0?} </td> <td align="center">{?=$eLoop->column1?}</td> <td align="center">{?=$eLoop->column2?}</td> <td align="center">{?=$eLoop->column3?}</td> </tr> </table> [/code]
< Template contents : tempo.sample.htm >
[code php;gutter:false] <?php $column[0]['column0'] = 'Country'; $column[0]['column1'] = 'Korea'; $column[0]['column2'] = 'USA'; $column[0]['column3'] = 'Germany'; $column[1]['column0'] = 'Capital city'; $column[1]['column1'] = 'Seoul'; $column[1]['column2'] = 'Washington DC'; $column[1]['column3'] = 'Berlin'; $column[2]['column0'] = 'Population'; $column[2]['column1'] = '49,000,000'; $column[2]['column2'] = '301,000,000'; $column[2]['column3'] = '82,000,000'; require_once('class.Tempo.php'); $tempo = new Tempo; $tempo->parse('eRoot', 'tempo.sample.htm'); $eLoop->outerHTML = $eLoop->assign($column); print $eRoot->assign(); $tempo->clear('eRoot'); ?> [/code]
< PHP code >
< Result >
attribute(string $name [, string $value])
This method get or set HTML tag attribute.
style(string $name [, string $value])
This method get or set HTML tag style.
tempo(string $name [, string $value])
This method get or set the value of tempo attribute statements.
[code html;gutter:false] <table border="1"> <tr style="height:50;"> <th bgcolor="#000066" style="color:white;">column1</th> <th bgcolor="#000066" style="color:white;">column2</th> <th bgcolor="#000066" style="color:white;">column3</th> </tr> <tr tempo:id="eLoop" bgcolor="silver" style="height:30;"> <td>{?=$column1?}</td> <td>{?=$column2?}</td> <td>{?=$column3?}</td> </tr> </table> [/code]
< Template contents for BLOCK element >
[code php;gutter:false] <?php require_once('class.Tempo.php'); $tempo = new Tempo; $tempo->parse('eRoot', 'templates/tempo.sample.htm'); $eLoop->attribute('bgcolor', 'yellow'); $eLoop->style('color', 'steelblue'); $loopID = $eLoop->tempo('id'); $column1 = 'apple'; $column2 = 'banana'; $column3 = 'orange'; print $eRoot->assign(); print '<p>loop ID = "' . $loopID . '"</p>'; $tempo->clear('eRoot'); ?> [/code]
< Process of BLOCK element >
< Result >

'phpsource > 템플릿' 카테고리의 다른 글

{Tempo}6.Download  (0) 2007.09.01
{Tempo}5.Example - Repeat Block  (0) 2007.09.01
{Tempo}3.Template contents  (0) 2007.09.01
{Tempo}2.Step by step  (0) 2007.09.01
{Tempo}1.Introduction  (0) 2007.09.01
Posted by 방글24