Source for file ex2.php

Documentation is available at ex2.php

  1. <?php
  2.  
  3. /**
  4. * example 2
  5. * demonstrates multiple level dynamic blocks
  6. *
  7. * $Id: fsource_XTemplate__ex2.php.html,v 1.3 2005/04/11 10:00:49 cocomp Exp $
  8. */
  9.  
  10. include_once('./xtemplate.class.php');
  11.  
  12. $xtpl = new XTemplate('ex2.xtpl');
  13.  
  14. /**
  15. * you can reference to array keys in the template file the following way:
  16. * {DATA.ID} or {DATA.NAME}
  17. * say we have an array from a mysql query with the following fields: ID, NAME, AGE
  18. */
  19. $rows = array();
  20. // add some data
  21. $rows[1]=array('ID'=>'38',
  22. 'NAME'=>'cocomp',
  23. 'AGE'=>'33'
  24. );
  25. // add some data
  26. $rows[2]=array('ID'=>'27',
  27. 'NAME'=>'linkhogthrob',
  28. 'AGE'=>'34'
  29. );
  30. // add some data
  31. $rows[3]=array('ID'=>'56',
  32. 'NAME'=>'pingu',
  33. 'AGE'=>'23'
  34. );
  35.  
  36. $rowsize = count($rows);
  37. for ($i = 1; $i <= $rowsize; $i++) {
  38. // assign array data
  39. $xtpl->assign('DATA', $rows[$i]);
  40. $xtpl->assign('ROW_NR', $i);
  41. // parse a row
  42. $xtpl->parse('main.table.row');
  43.  
  44. // another way to do it would be:
  45. /*
  46. $xtpl->insert_loop('main.table.row', array('DATA'=>$rows[$i],
  47. 'ROW_NR'=>$i
  48. ));
  49. */
  50. }
  51.  
  52. // parse the table
  53. $xtpl->parse('main.table');
  54. $xtpl->parse('main');
  55. $xtpl->out('main');
  56.  
  57. /*
  58. $Log: fsource_XTemplate__ex2.php.html,v $
  59. Revision 1.3 2005/04/11 10:00:49 cocomp
  60. Added restart() method sf:641407 feature request
  61. Revision 1.2 2005/04/07 12:02:52 cocomp
  62. MAJOR UPDATE: E_ALL safe, better internal documentation, code readability ++, many bugfixes and new features - considered stable
  63. Revision 1.1 2001/07/11 10:49:25 cranx
  64. *** empty log message ***
  65. Revision 1.2 2001/03/26 23:25:02 cranx
  66. added keyword expansion to be more clear
  67. */
  68.  
  69. ?>

Documentation generated on Mon, 11 Apr 2005 10:59:08 +0100 by phpDocumentor 1.3.0RC3