XiTemplate Home Page XiTemplate
[ class tree: XiTemplate ] [ index: XiTemplate ] [ all elements ]

Example usage of $nullValue

  1. <?php
  2. /*include the class*/
  3. include_once('../class.XiTemplate.php');
  4. /*instantiate the class and pass the path to your html template file*/
  5. $xitpl = new XiTemplate('templates/nullValue.tpl');
  6. /*assign a value to a template variable.*\
  7. /*In this example {NAME} will be replaced with "XiTemplate"*/
  8. $xitpl->assign('NAME', 'XiTemplate');
  9. /*multidimensional array*/
  10. $myArray = array
  11. (
  12. 'name' => 'Jim',
  13. 'lastName' => 'Grill',
  14. 'address' => array
  15. (
  16. 'street' => 'One XiTemplate Way',
  17. 'city' => 'Paradise',
  18. 'state' => '', /* No state specified. This is a null value.*/
  19. 'zip' => '12345'
  20. ),
  21. 'age' => 'too old'
  22. );
  23. /*assign the array to a template variable*/
  24. $xitpl->assign('MYARRAY', $myArray);
  25. /*We don't want to display null values so we assign 'Unknown' instead*/
  26. /*This can be done at any time as long it's before the current block is parsed*/
  27. $xitpl->nullValue = 'Unknown';
  28. /*parse the first block*/
  29. $xitpl->parse('main.firstperson');
  30. /*null values will be ok from this point so we reset it to ''.*/
  31. /*This can be done at anytime before the next block is parsed so we*/
  32. /*could have done it on line 60 if we wanted to.*/
  33. $xitpl->nullValue = '';
  34. /*multidimensional array*/
  35. $myArray = array
  36. (
  37. 'name' => 'Travis',
  38. 'lastName' => 'Miller',
  39. 'address' => array
  40. (
  41. 'street' => 'One Coder\'s Way',
  42. 'city' => 'Linux Valley',
  43. 'state' => '', /* No state specified. This is a null value.*/
  44. 'zip' => '54321'
  45. ),
  46. 'age' => 'too young'
  47. );
  48. /*assign the array to a template variable*/
  49. $xitpl->assign('MYARRAY', $myArray);
  50. /*parse the second block*/
  51. $xitpl->parse('main.secondperson');
  52. /*parse the "main" block of the page (the whole page)*/
  53. $xitpl->parse('main');
  54. /*send the final page out to the browser*/
  55. $xitpl->out('main');
  56. ?>

Documentation generated on Fri, 20 Aug 2004 10:57:44 -0500 by phpDocumentor 1.3.0RC3