phpsource/템플릿2007. 9. 1. 17:17
written: Sep 1 2007
Learn howto step by step
The main steps are:
  1. Prepare Template contents
  2. Include the tempo class(tempo)
  3. Instantiate class
  4. Parse the template contents
  5. Set variable
  6. Assign the template contents
  7. Output the assigned contents
  8. Clear the parsed contents
1. Prepare Template contents
A template contents(file or string) is basically an HTML document that also contain variable substitutions (enclosed with the begin tag {?= and end tag ?}) and special HTML tag attributes "tempo:statemants".
[code html;gutter:false] <table> <tr> <th>column1</th> <th>column2</th> <th>column3</th> </tr> <tr tempo:id="eLoop"> <td>{?=$column1?}</td> <td>{?=$column2?}</td> <td>{?=$column3?}</td> </tr> </table> [/code]
2. Include the tempo class
You should first include the tempo class(class.tempo.php) by require_once() or include_once(). Here is how you create an instance of Tempo in your PHP scripts.
[code php;gutter:false] require_once('somewhere/class.Tempo.php'); [/code]
3. Instantiate class
Instantiate class using operator new.
[code php;gutter:false] $tempo = new Tempo; [/code]
4. Parse the template contents
Parse the template contents(file or string) by its method parse() or parse_str(). First parameter is the template handle corresponding the template contents to be processed.
[code php;gutter:false] $tempo->parse('eRoot', 'templates/tempo.sample.htm'); [/code]
5. Set variable
There is no method for setting variable. You are able to use global variables in PHP.
[code php;gutter:false] $column1 = 'apple'; $column2 = 'banana'; $column3 = 'orange'; [/code]
6. Assign the template contents
This inserts the values of all the variables that have been set into the template. First parameter of parse() method, template handle name is the created template object name.
[code php;gutter:false] $resultHTML = $eRoot->assign(); [/code]
7. Output the assigned contents
You are able to use the PHP built-in function print or etc to output the assigned contents.
[code php;gutter:false] print $resultHTML; [/code]
8. Clear the parsed contents
This 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]

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

{Tempo}4.Class Methods  (0) 2007.09.01
{Tempo}3.Template contents  (0) 2007.09.01
{Tempo}1.Introduction  (0) 2007.09.01
{후키템플릿}9.5.게시판 목록보기 구현  (0) 2006.11.03
{후키템플릿}8.3.필터 상수  (0) 2006.11.03
Posted by 방글24