Leandro Lucarella ------------------------------------------------------------------------------- $Id: Tpl.php 584 2004-07-30 05:50:10Z luca $ -----------------------------------------------------------------------------*/ //{{{Explanation of this example. // This example will create an html page with a header, body and a footer. // In order to do this, I will use three template groups (header, body, footer). // All this templates are located in TPLS directory. //}}} //{{{ Require Once. require_once 'MLIB/Tpl/FileDir.php'; //}}} //{{{ The following variables are used as examples. $table_width = 'width="700"'; $img_source = './img/logo.jpg'; //}}} //{{{ Create a page from a template. $HIT =& new MLIB_Tpl_FileDir ('TPLS'); // Where TPLS is the subdirectory where I'll // put my html_templates. //}}} //{{{ Show this source if (@$_GET['source']) { $HEADER = ''; $FOOTER = ''; $SOURCE = ''; $BODY = highlight_file($_SERVER['SCRIPT_FILENAME'], true); } //}}} //{{{ Example else { //{{{ Add header group of templates. $HIT->pushGroup('header'); //{{{ First ROW //{{{ Obtain the data cells of the first row. $cells = $HIT->parse('cell', array ( 'ATTR' => 'width="20%" align="center"', //Sets the width of the cell. 'CELL' => $HIT->parse('logo', //Add the logo image to this cell. array( 'SRC' => $img_source, //Source of the image. 'ATTR' => 'border="0"', //Image attributes 'ALT' => 'LOGO' //Alternative text. ) ) ) ); $cells.= $HIT->parse('cell', array ( 'ATTR' => 'width="80%" align="center"', //Sets the width of the cell. 'CELL' => 'MLIB_Tpl_FileDir Example' //Title. ) ); //}}} // Obtain the first row of the header table. $rows = $HIT->parse('row', 'CELL', $cells); //}}} //{{{ Second Row // Obtain the data cells of the first row. $cells = $HIT->parse('cell', array ( 'ATTR' => 'colspan="2" align="center"', //Sets the width of the cell. 'CELL' => 'This is the second row of the header table.' ) ); // Obtain the first row of the header table. $rows.= $HIT->parse('row', 'CELL', $cells); //}}} // Obtain the parsed templates and add it to the header "main" template. $HEADER = $HIT->parse( 'table', array ( 'ATTR' => $table_width . ' border="1" align="center"', 'ROWS' => $rows ) ); // Remove from the group stack the header group. $HIT->popGroup('header'); //}}} //{{{ Add body group of templates. $HIT->pushGroup('body'); //{{{ First ROW $cells = $HIT->parse('cell', array ( 'ATTR' => 'valign="center" align="center" height="370"', //Sets the width of the cell. 'CELL' => 'BODY' //Body Content ) ); // Obtain the first row of the header table. $rows = $HIT->parse('row', 'CELL', $cells); //}}} // Obtain the parsed templates and add it to the header "main" template. $BODY = $HIT->parse( 'table', array ( 'ATTR' => $table_width . ' border="0" align="center"', 'ROWS' => $rows ) ); // Remove from the group stack the header group. $HIT->popGroup('body'); //}}} //{{{ Add footer group of templates. $HIT->pushGroup('footer'); //{{{ First ROW //{{{ Obtain the data cells of the first row. $cells = $HIT->parse('cell', array ( 'ATTR' => 'align="center"', //Sets the width of the cell. 'CELL' => $HIT->parse( 'text', 'LINK', $HIT->parse('link_meconlib_dev') ) ) ); //}}} // Obtain the first row of the header table. $rows = $HIT->parse('row', 'CELL', $cells); //}}} // Obtain the parsed templates and add it to the header "main" template. $FOOTER = $HIT->parse( 'table', array ( 'ATTR' => $table_width . ' border="1" align="center"', 'ROWS' => $rows ) ); // Remove from the group stack the header group. $HIT->popGroup('footer'); //}}} //{{{ Add SOURCE group of templates. $HIT->pushGroup('source'); // Obtain the parsed templates and add it to the header "main" template. $SOURCE = $HIT->parse('div'); // Remove from the group stack the header group. $HIT->popGroup('source'); //}}} } //}}} //{{{ Add all the parsed templates to the main template. $RESULT = $HIT->parse( 'body', array ( 'TITLE' => 'MLIB_Tpl_HIT Test', 'BODY' => $HEADER . $BODY . $FOOTER, 'SOURCE' => $SOURCE ) ); //}}} //{{{ Display the result. echo $RESULT; //}}} ?>