- <?php
- /*include the class*/
- include_once('../class.XiTemplate.php');
-
- /*instantiate the class and pass the path to your html template file*/
- $xitpl = new XiTemplate('templates/construct.tpl');
-
- /*assign a value to a template variable.*\
- /*In this example {NAME} will be replaced with "XiTemplate"*/
- $xitpl->assign('NAME', 'XiTemplate');
-
- /*the following template exists only in the buffer*/
- /*this template could have come from a database or some other data source*/
- $content = <<<EOF
- <!-- BEGIN: main -->
- <table border="0" cellpadding="10" cellspacing="0" bgcolor="#FFFFFF">
- <tr>
- <td>
- <p>This is an example of a template that comes from the buffer.</p>
- <p>This template could come from a database or some other data source.</p>
- <p>This template can have variables and blocks just like any other template.</p>
- <p>Here is a variable: "{VARIABLE}"</p>
- <!-- BEGIN: sub -->
- <p>This text is a sub block of template2.</p>
- <!-- END: sub -->
- </td>
- </tr>
- </table>
- <!-- END: main -->
- EOF;
- /*instantiate a second template (template 2)*/
- /*in this case the template comes from buffer instead of a */
- /*file as in the case of the first template*/
- $xitpl2 = new XiTemplate($content);
-
- /*assign a variable to template 2*/
- $xitpl2->assign('VARIABLE', 'I\'m a variable');
-
- /*parse a sub block within template 2*/
- $xitpl2->parse('main.sub');
-
- /*parse the main block of template 2 (the whole page)*/
- $xitpl2->parse('main');
-
- /*assign the text from template 2 to a template variable in template 1*/
- $xitpl->assign('CONTENT', $xitpl2->text('main'));
-
- /*parse the "main" block of template 1 (the whole page)*/
- $xitpl->parse('main');
-
- /*send the final page out to the browser*/
- $xitpl->out('main');
- ?>