1 <?php /* vim: set binary noeol et ts=4 sw=4 tw=80 foldmethod=marker:
2 -------------------------------------------------------------------------------
4 -------------------------------------------------------------------------------
5 This file is part of mlib.
7 mlib is free software; you can redistribute it and/or modify it under
8 the terms of the GNU Lesser General Public License as published by the Free
9 Software Foundation; either version 2 of the License, or (at your option)
12 mlib is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
17 You should have received a copy of the GNU Lesser General Public License; if
18 not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19 Boston, MA 02111-1307 USA
20 -------------------------------------------------------------------------------
21 Created: jue jul 29 09:42:56 ART 2004
22 Authors: MartÃn Marrese <m_marrese@argentina.com>
23 Leandro Lucarella <luca@llucax.hn.org>
24 -------------------------------------------------------------------------------
26 -----------------------------------------------------------------------------*/
28 //{{{Explanation of this example.
29 // This example will create an html page with a header, body and a footer.
30 // In order to do this, I will use three template groups (header, body, footer).
31 // All this templates are located in TPLS directory.
35 ini_set('include_path', '../../../lib:' . ini_get('include_path'));
36 require_once 'MLIB/Tpl/FileDir.php';
39 //{{{ The following variables are used as examples.
40 $table_width = 'width="700"';
41 $img_source = './img/logo.jpg';
44 //{{{ Create a page from a template.
45 $TPL =& new MLIB_Tpl_FileDir ('TPLS'); // Where TPLS is the subdirectory where I'll
46 // put my html_templates.
49 //{{{ Show this source
55 $BODY = highlight_file($_SERVER['SCRIPT_FILENAME'], true);
62 //{{{ Add header group of templates.
63 $TPL->pushGroup('header');
66 //{{{ Obtain the data cells of the first row.
67 $cells = $TPL->parse('cell',
69 'ATTR' => 'width="20%" align="center"', //Sets the width of the cell.
70 'CELL' => $TPL->parse('logo', //Add the logo image to this cell.
72 'SRC' => $img_source, //Source of the image.
73 'ATTR' => 'border="0"', //Image attributes
74 'ALT' => 'LOGO' //Alternative text.
79 $cells.= $TPL->parse('cell',
81 'ATTR' => 'width="80%" align="center"', //Sets the width of the cell.
82 'CELL' => 'MLIB_Tpl_FileDir Example' //Title.
87 // Obtain the first row of the header table.
88 $rows = $TPL->parse('row', 'CELL', $cells);
92 // Obtain the data cells of the first row.
93 $cells = $TPL->parse('cell',
95 'ATTR' => 'colspan="2" align="center"', //Sets the width of the cell.
96 'CELL' => '<b>This is the second row of the header table.</b>'
100 // Obtain the first row of the header table.
101 $rows.= $TPL->parse('row', 'CELL', $cells);
104 // Obtain the parsed templates and add it to the header "main" template.
105 $HEADER = $TPL->parse(
108 'ATTR' => $table_width . ' border="1" align="center"',
112 // Remove from the group stack the header group.
113 $TPL->popGroup('header');
116 //{{{ Add body group of templates.
117 $TPL->pushGroup('body');
120 $cells = $TPL->parse('cell',
122 'ATTR' => 'valign="center" align="center" height="370"', //Sets the width of the cell.
123 'CELL' => '<font size="1">BODY</font>' //Body Content
127 // Obtain the first row of the header table.
128 $rows = $TPL->parse('row', 'CELL', $cells);
131 // Obtain the parsed templates and add it to the header "main" template.
135 'ATTR' => $table_width . ' border="0" align="center"',
139 // Remove from the group stack the header group.
140 $TPL->popGroup('body');
143 //{{{ Add footer group of templates.
144 $TPL->pushGroup('footer');
147 //{{{ Obtain the data cells of the first row.
148 $cells = $TPL->parse('cell',
150 'ATTR' => 'align="center"', //Sets the width of the cell.
151 'CELL' => $TPL->parse(
154 $TPL->parse('link_meconlib_dev')
160 // Obtain the first row of the header table.
161 $rows = $TPL->parse('row', 'CELL', $cells);
165 // Obtain the parsed templates and add it to the header "main" template.
166 $FOOTER = $TPL->parse(
169 'ATTR' => $table_width . ' border="1" align="center"',
173 // Remove from the group stack the header group.
174 $TPL->popGroup('footer');
177 //{{{ Add SOURCE group of templates.
178 $TPL->pushGroup('source');
180 // Obtain the parsed templates and add it to the header "main" template.
181 $SOURCE = $TPL->parse('div');
182 // Remove from the group stack the header group.
183 $TPL->popGroup('source');
188 //{{{ Add all the parsed templates to the main template.
189 $RESULT = $TPL->parse(
192 'TITLE' => 'MLIB_Tpl_FileDir Test',
193 'BODY' => $HEADER . $BODY . $FOOTER,
199 //{{{ Display the result.