Source for file ex8.php

Documentation is available at ex8.php

  1. <?php
  2.  
  3. /**
  4. * example 8
  5. * demonstrates how to do good table rows and columns :)
  6. *
  7. * @package XTemplate_Examples
  8. * @author Jeremy Coates [cocomp@users.sourceforge.net]
  9. * @copyright Jeremy Coates 2007
  10. * @see license.txt BSD license
  11. * @link $HeadURL: https://xtpl.svn.sourceforge.net/svnroot/xtpl/trunk/ex8.php $
  12. * @version $Id: ex8.php 21 2007-05-29 18:01:15Z cocomp $
  13. */
  14.  
  15. require_once('xtemplate.class.php');
  16. $xtpl = new XTemplate('ex8.xtpl');
  17.  
  18. // Config
  19. $num_columns = 5;
  20.  
  21. // This could be from e.g. num_rows from a database result set
  22. $max_items = 26;
  23. // End Config
  24.  
  25. $i = 0;
  26.  
  27. // Build the main table
  28. while ($i < $max_items) {
  29.  
  30. $i ++;
  31.  
  32. // Assign the content
  33. $xtpl->assign('stuff', array('item' => $i));
  34.  
  35. // Parse the cell
  36. $xtpl->parse('main.table.row.cell');
  37.  
  38. // Use modulus of row length to decide if we wrap to next row
  39. if (($i % $num_columns) == 0) {
  40. $xtpl->parse('main.table.row');
  41. }
  42.  
  43. }
  44.  
  45. // Deal with the last table row
  46. $remainder = $i % $num_columns;
  47.  
  48. if (($remainder) != 0) {
  49.  
  50. // Wipe the last value (using &nbsp; for illustration only)
  51. $xtpl->assign('stuff', array('item' => '&nbsp;'));
  52.  
  53. // Add blank cells as needed to keep the table complete
  54. for ($j = $remainder; $j < $num_columns; $j ++) {
  55. $xtpl->parse('main.table.row.cell');
  56. }
  57.  
  58. $xtpl->parse('main.table.row');
  59. }
  60.  
  61. // Output
  62. $xtpl->parse('main.table');
  63. $xtpl->parse('main');
  64. $xtpl->out('main');
  65.  
  66. ?>

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