XiTemplate Home Page XiTemplate
[ class tree: XiTemplate ] [ index: XiTemplate ] [ all elements ]
Prev Next
Recursive Parse

Recursive Parse

The recursive parse - parsing everything

The rparse() Method

In the previous pages we have become familiar with the parse() method. Now we'll take a look at a powerful alternative, rparse().

For this example we'll use the same template we used to build our table in the last example.

  1. <?php
  2. /*include the class*/
  3. include_once('../class.XiTemplate.php');
  4.  
  5. /*instantiate the class and pass the path to your HTML template file*/
  6. $xitpl = new XiTemplate('templates/parse.tpl');
  7.  
  8. /*assign a value to a template variable.*\
  9. /*In this example {NAME} will be replaced with "XiTemplate"*/
  10. $xitpl->assign('NAME', 'XiTemplate');
  11.  
  12. /*let's make dynamically make a table*/
  13. $rows = 1;
  14. $cols = 1;
  15.  
  16. $xitpl->assign('VARIABLE', 'row: 1, column: 1');
  17.  
  18. /* ---- recursively ---- */
  19. /* parse the "main" block of the template (the whole page)*/
  20. $xitpl->rparse('main');
  21.  
  22. /*send the final page out to the browser*/
  23. $xitpl->out('main');
  24. ?>

So what the heck happened? Well, let's say you had some pretty complicated code and at some point in your code you realized that there may be a time when only one record is returned from a query or only one value may exist in code that is built for many. This is just an example. There may be a hundred other uses for rparse().

In the preceding example we determined that there was only going to be one column and one row. Rather than go through all the complication of running two "for" loops and parsing multiple blocks we just assigned our one template variable and used rparse() to parse the whole darn thing one time.

Recursive parsing will parse all the blocks within the parent block called by rparse().

Next up... file includes!

To be continued soon.

Prev Up Next
parsing blocks XiTemplate Manual

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