XiTemplate Home Page XiTemplate
[ class tree: XiTemplate ] [ index: XiTemplate ] [ all elements ]

Example usage of __construct()

  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/construct.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. /*the following template exists only in the buffer*/
  13. /*this template could have come from a database or some other data source*/
  14. $content = <<<EOF
  15. <!-- BEGIN: main -->
  16. <table border="0" cellpadding="10" cellspacing="0" bgcolor="#FFFFFF">
  17. <tr>
  18. <td>
  19. <p>This is an example of a template that comes from the buffer.</p>
  20. <p>This template could come from a database or some other data source.</p>
  21. <p>This template can have variables and blocks just like any other template.</p>
  22. <p>Here is a variable: "{VARIABLE}"</p>
  23. <!-- BEGIN: sub -->
  24. <p>This text is a sub block of template2.</p>
  25. <!-- END: sub -->
  26. </td>
  27. </tr>
  28. </table>
  29. <!-- END: main -->
  30. EOF;
  31. /*instantiate a second template (template 2)*/
  32. /*in this case the template comes from buffer instead of a */
  33. /*file as in the case of the first template*/
  34. $xitpl2 = new XiTemplate($content);
  35.  
  36. /*assign a variable to template 2*/
  37. $xitpl2->assign('VARIABLE', 'I\'m a variable');
  38.  
  39. /*parse a sub block within template 2*/
  40. $xitpl2->parse('main.sub');
  41.  
  42. /*parse the main block of template 2 (the whole page)*/
  43. $xitpl2->parse('main');
  44.  
  45. /*assign the text from template 2 to a template variable in template 1*/
  46. $xitpl->assign('CONTENT', $xitpl2->text('main'));
  47.  
  48. /*parse the "main" block of template 1 (the whole page)*/
  49. $xitpl->parse('main');
  50.  
  51. /*send the final page out to the browser*/
  52. $xitpl->out('main');
  53. ?>

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