Source for file ex3.php

Documentation is available at ex3.php

  1. <?php
  2.  
  3. /**
  4. * example 3
  5. * autoreset
  6. *
  7. * @package XTemplate_Examples
  8. * @author Barnabas Debreceni [cranx@users.sourceforge.net]
  9. * @copyright Barnabas Debreceni 2000-2001
  10. * @author Jeremy Coates [cocomp@users.sourceforge.net]
  11. * @copyright Jeremy Coates 2002-2007
  12. * @see license.txt LGPL / BSD license
  13. * @link $HeadURL: https://xtpl.svn.sourceforge.net/svnroot/xtpl/trunk/ex3.php $
  14. * @version $Id: ex3.php 16 2007-01-11 03:02:49Z cocomp $
  15. */
  16.  
  17. include_once('./xtemplate.class.php');
  18.  
  19. $xtpl = new XTemplate('ex3.xtpl');
  20.  
  21. // this is the code from example 2:
  22.  
  23. $rows = array();
  24.  
  25. // add some data
  26. $rows[1]=array('ID'=>'38',
  27. 'NAME'=>'cocomp',
  28. 'AGE'=>'33'
  29. );
  30.  
  31. // add some data
  32. $rows[2]=array('ID'=>'27',
  33. 'NAME'=>'linkhogthrob',
  34. 'AGE'=>'34'
  35. );
  36.  
  37. // add some data
  38. $rows[3]=array('ID'=>'56',
  39. 'NAME'=>'pingu',
  40. 'AGE'=>'23'
  41. );
  42.  
  43. $rowsize = count($rows);
  44.  
  45. for ($i=1; $i<=$rowsize; $i++) {
  46.  
  47. // assign array data
  48. $xtpl->assign('DATA', $rows[$i]);
  49. $xtpl->assign('ROW_NR', $i);
  50.  
  51. // parse a row
  52. $xtpl->parse('main.table.row');
  53. }
  54.  
  55. // parse the table (Table 1)
  56. $xtpl->parse('main.table');
  57.  
  58. /**
  59. * now, if you wanted to parse the table once again with the old rows,
  60. * and put one more $xtpl->parse('main.table') line, it wouldn't do it
  61. * becuase the sub-blocks were resetted (normal operation)
  62. * to parse the same block two or more times without having the sub-blocks resetted,
  63. * you should use clear_autoreset();
  64. * to switch back call set_autoreset();
  65. */
  66.  
  67. $xtpl->clear_autoreset();
  68.  
  69. for ($i = 1; $i <= $rowsize; $i++) {
  70.  
  71. // assign array data
  72. $xtpl->assign('DATA', $rows[$i]);
  73. $xtpl->assign('ROW_NR', $i);
  74.  
  75. // parse a row
  76. $xtpl->parse('main.table.row');
  77. }
  78.  
  79. // parse the table (Table 2)
  80. $xtpl->parse('main.table');
  81.  
  82. // Turn the autoreset back on - the sub-block will be reset after the next table parse
  83. $xtpl->set_autoreset();
  84.  
  85. // parse it one more time.. the rows are still there from the last parse of table (2)
  86. // the set_autoreset on the previous line means the rows are cleared during this parse (sub-block reset) (Table 3)
  87. $xtpl->parse('main.table');
  88.  
  89. // re-parse the table block (Table 4)
  90. $xtpl->parse('main.table');
  91.  
  92. $xtpl->parse('main');
  93. $xtpl->out('main');
  94.  
  95. ?>

Documentation generated on Tue, 29 May 2007 19:29:34 +0100 by phpDocumentor 1.3.0RC3