Leandro Lucarella ------------------------------------------------------------------------------- $Id$ -----------------------------------------------------------------------------*/ //{{{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. ini_set('include_path', '../../../lib:' . ini_get('include_path')); 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. $TPL =& 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. $TPL->pushGroup('header'); //{{{ First ROW //{{{ Obtain the data cells of the first row. $cells = $TPL->parse('cell', array ( 'ATTR' => 'width="20%" align="center"', //Sets the width of the cell. 'CELL' => $TPL->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.= $TPL->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 = $TPL->parse('row', 'CELL', $cells); //}}} //{{{ Second Row // Obtain the data cells of the first row. $cells = $TPL->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.= $TPL->parse('row', 'CELL', $cells); //}}} // Obtain the parsed templates and add it to the header "main" template. $HEADER = $TPL->parse( 'table', array ( 'ATTR' => $table_width . ' border="1" align="center"', 'ROWS' => $rows ) ); // Remove from the group stack the header group. $TPL->popGroup('header'); //}}} //{{{ Add body group of templates. $TPL->pushGroup('body'); //{{{ First ROW $cells = $TPL->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 = $TPL->parse('row', 'CELL', $cells); //}}} // Obtain the parsed templates and add it to the header "main" template. $BODY = $TPL->parse( 'table', array ( 'ATTR' => $table_width . ' border="0" align="center"', 'ROWS' => $rows ) ); // Remove from the group stack the header group. $TPL->popGroup('body'); //}}} //{{{ Add footer group of templates. $TPL->pushGroup('footer'); //{{{ First ROW //{{{ Obtain the data cells of the first row. $cells = $TPL->parse('cell', array ( 'ATTR' => 'align="center"', //Sets the width of the cell. 'CELL' => $TPL->parse( 'text', 'LINK', $TPL->parse('link_meconlib_dev') ) ) ); //}}} // Obtain the first row of the header table. $rows = $TPL->parse('row', 'CELL', $cells); //}}} // Obtain the parsed templates and add it to the header "main" template. $FOOTER = $TPL->parse( 'table', array ( 'ATTR' => $table_width . ' border="1" align="center"', 'ROWS' => $rows ) ); // Remove from the group stack the header group. $TPL->popGroup('footer'); //}}} //{{{ Add SOURCE group of templates. $TPL->pushGroup('source'); // Obtain the parsed templates and add it to the header "main" template. $SOURCE = $TPL->parse('div'); // Remove from the group stack the header group. $TPL->popGroup('source'); //}}} } //}}} //{{{ Add all the parsed templates to the main template. $RESULT = $TPL->parse( 'body', array ( 'TITLE' => 'MLIB_Tpl_FileDir Test', 'BODY' => $HEADER . $BODY . $FOOTER, 'SOURCE' => $SOURCE ) ); //}}} //{{{ Display the result. echo $RESULT; //}}} ?>