XiTemplate Home Page XiTemplate
[ class tree: XiTemplate ] [ index: XiTemplate ] [ all elements ]
Prev Next
Quick Start

Quick Start

Quick start for the impatient

Example Usage

The following examples include PHP code, an HTML template, and the resulting HTML after parsing.

Example PHP Code

  1. <?php
  2. /*include the class*/
  3. include_once('../class.XiTemplate.php');
  4.  
  5. /*instantiate the class and pass the path to your HTML template file*/
  6. $xitpl = new XiTemplate('templates/assign.tpl');
  7.  
  8. /*assign a value to a template variable.*\
  9. /*In this example {NAME} will be replaced with "XiTemplate"*/
  10. $xitpl->assign('NAME', 'XiTemplate');
  11.  
  12. /*multidimensional array*/
  13. $myArray = array
  14. (
  15. 'name' => 'Jim',
  16. 'lastName' => 'Grill',
  17. 'address' => array
  18. (
  19. 'street' => 'One XiTemplate Way',
  20. 'city' => 'Paradise',
  21. 'state' => 'Hawaii',
  22. 'zip' => '12345'
  23. ),
  24. 'age' => 'too old'
  25. );
  26.  
  27. /*assign the array to a template variable*/
  28. $xitpl->assign('MYARRAY', $myArray);
  29.  
  30. /*parse the "main" block of the page (the whole page)*/
  31. $xitpl->parse('main');
  32.  
  33. /*send the final page out to the browser*/
  34. $xitpl->out('main');
  35. ?>

Example Template Code

<!-- BEGIN: main -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>XiTemplate Manual - assign()</title>
</head>

<body>

<h1>XiTemplate</h1>

<p>Hi. My name  is {NAME}.</p>

<p>This example was written by:</p>

<p>{MYARRAY.name} {MYARRAY.lastName}<br>
{MYARRAY.address.street}<br>
{MYARRAY.address.city}, {MYARRAY.address.state} {MYARRAY.address.zip}
</p>

</body>
</html>

<!-- END: main -->

Example Resulting HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>XiTemplate Manual - assign()</title>
</head>

<body>

<h1>XiTemplate</h1>

<p>Hi. My name  is XiTemplate.</p>

<p>This example was written by:</p>

<p>Jim Grill<br>
One XiTemplate Way<br>
Paradise, Hawaii 12345
</p>

</body>
</html>

The preceding example is very basic and is not at all meant as an exhaustive example of what XiTemplate is capable of.

Please continue reading for a better understanding of XiTemplate's features.

Prev Up Next
XiTemplate Manual XiTemplate Manual Template Anatomy

Documentation generated on Fri, 20 Aug 2004 10:57:40 -0500 by phpDocumentor 1.3.0RC3