Source for file ex3.php

Documentation is available at ex3.php

  1. <?php
  2.  
  3. /**
  4. * example 3
  5. * autoreset
  6. *
  7. * $Id: fsource_XTemplate__ex3.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('ex3.xtpl');
  13.  
  14. // this is the code from example 2:
  15.  
  16. $rows = array();
  17. // add some data
  18. $rows[1]=array('ID'=>'38',
  19. 'NAME'=>'cocomp',
  20. 'AGE'=>'33'
  21. );
  22. // add some data
  23. $rows[2]=array('ID'=>'27',
  24. 'NAME'=>'linkhogthrob',
  25. 'AGE'=>'34'
  26. );
  27. // add some data
  28. $rows[3]=array('ID'=>'56',
  29. 'NAME'=>'pingu',
  30. 'AGE'=>'23'
  31. );
  32.  
  33. $rowsize = count($rows);
  34. for ($i=1; $i<=$rowsize; $i++) {
  35. // assign array data
  36. $xtpl->assign('DATA', $rows[$i]);
  37. $xtpl->assign('ROW_NR', $i);
  38. // parse a row
  39. $xtpl->parse('main.table.row');
  40. }
  41. // parse the table (Table 1)
  42. $xtpl->parse('main.table');
  43.  
  44. /**
  45. * now, if you wanted to parse the table once again with the old rows,
  46. * and put one more $xtpl->parse('main.table') line, it wouldn't do it
  47. * becuase the sub-blocks were resetted (normal operation)
  48. * to parse the same block two or more times without having the sub-blocks resetted,
  49. * you should use clear_autoreset();
  50. * to switch back call set_autoreset();
  51. */
  52. $xtpl->clear_autoreset();
  53. for ($i = 1; $i <= $rowsize; $i++) {
  54. // assign array data
  55. $xtpl->assign('DATA', $rows[$i]);
  56. $xtpl->assign('ROW_NR', $i);
  57. // parse a row
  58. $xtpl->parse('main.table.row');
  59. }
  60. // parse the table (Table 2)
  61. $xtpl->parse('main.table');
  62. // Turn the autoreset back on - the sub-block will be reset after the next table parse
  63. $xtpl->set_autoreset();
  64. // parse it one more time.. the rows are still there from the last parse of table (2)
  65. // the set_autoreset on the previous line means the rows are cleared during this parse (sub-block reset) (Table 3)
  66. $xtpl->parse('main.table');
  67. // re-parse the table block (Table 4)
  68. $xtpl->parse('main.table');
  69.  
  70. $xtpl->parse('main');
  71. $xtpl->out('main');
  72.  
  73. /*
  74. $Log: fsource_XTemplate__ex3.php.html,v $
  75. Revision 1.3 2005/04/11 10:00:49 cocomp
  76. Added restart() method sf:641407 feature request
  77. Revision 1.2 2005/04/07 12:02:52 cocomp
  78. MAJOR UPDATE: E_ALL safe, better internal documentation, code readability ++, many bugfixes and new features - considered stable
  79. Revision 1.1 2001/07/11 10:49:25 cranx
  80. *** empty log message ***
  81. Revision 1.2 2001/03/26 23:25:02 cranx
  82. added keyword expansion to be more clear
  83. */
  84.  
  85. ?>

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