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. * @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/ex2.php $
  14. * @version $Id: ex2.php 16 2007-01-11 03:02:49Z cocomp $
  15. */
  16.  
  17. include_once('./xtemplate.class.php');
  18.  
  19. $xtpl = new XTemplate('ex2.xtpl');
  20.  
  21. /**
  22. * you can reference to array keys in the template file the following way:
  23. * {DATA.ID} or {DATA.NAME}
  24. * say we have an array from a mysql query with the following fields: ID, NAME, AGE
  25. */
  26. $rows = array();
  27.  
  28. // add some data
  29. $rows[1]=array('ID'=>'38',
  30. 'NAME'=>'cocomp',
  31. 'AGE'=>'33'
  32. );
  33.  
  34. // add some data
  35. $rows[2]=array('ID'=>'27',
  36. 'NAME'=>'linkhogthrob',
  37. 'AGE'=>'34'
  38. );
  39.  
  40. // add some data
  41. $rows[3]=array('ID'=>'56',
  42. 'NAME'=>'pingu',
  43. 'AGE'=>'23'
  44. );
  45.  
  46. $rowsize = count($rows);
  47.  
  48. for ($i = 1; $i <= $rowsize; $i++) {
  49.  
  50. // assign array data
  51. $xtpl->assign('DATA', $rows[$i]);
  52. $xtpl->assign('ROW_NR', $i);
  53.  
  54. // parse a row
  55. $xtpl->parse('main.table.row');
  56.  
  57. // another way to do it would be:
  58. /*
  59. $xtpl->insert_loop('main.table.row', array('DATA'=>$rows[$i],
  60. 'ROW_NR'=>$i
  61. ));
  62. */
  63.  
  64. }
  65.  
  66. // parse the table
  67. $xtpl->parse('main.table');
  68.  
  69. $xtpl->parse('main');
  70. $xtpl->out('main');
  71.  
  72. ?>

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