Location: PHPKode > scripts > Phptempt > phptempt/tutorial.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"><HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">
<META NAME="GENERATOR" CONTENT="Adobe FrameMaker 6.0/HTML Export Filter">
<LINK REL="STYLESHEET" HREF="tutorial.css" CHARSET="ISO-8859-1" TYPE="text/css">
<TITLE>
 PhpTempt Tutorial
</TITLE>
</HEAD>
<BODY BGCOLOR="#ffffff">
<DIV>
<H1 CLASS="Titel">
<A NAME="pgfId-999206"></A><EM CLASS="Kap-">
PhpTempt</EM>
 Tutorial</H1>
<P CLASS="Untertitel">
<A NAME="pgfId-1001501"></A>Version 30</P>
<P CLASS="Untertitel">
<A NAME="pgfId-1001858"></A>Hans K&ouml;rber</P>
<DIV>
<H3 CLASS="Ueberschrift-2-NZ">
<A NAME="pgfId-1001678"></A>Disclaimer</H3>
<P CLASS="Haupttext">
<A NAME="pgfId-1001778"></A>THE INFORMATIONS IN THIS TUTORIAL ARE SUPPLIED ON AN &quot;AS IS&quot; BASIS WITHOUT WARRANTY OF ANY KIND, AND OBJECTIVITY SHALL HAVE NO LIABILITY OR OBLIGATION FOR DAMAGES, INCLUDING BUT NOT LIMITED TO ACTUAL, INDIRECT CONSEQUENTIAL AND INCIDENTIAL DAMAGES OCCURING OUT OF OR IN CONNECTION WITH THE USE OF THE PROGRAM, WITHOUT REGARD TO WHETHER SUCH DAMAGES WERE FORESEEABLE.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1001761"></A>First issued on Wednesday, 4. April 2001</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1001859"></A>Last updated on Monday, 6. January 2003</P>
</DIV>
<DIV>
<H2 CLASS="Ueberschrift-1">
<A NAME="pgfId-7444"></A>Table of contents</H2>
<DIV>
<H3 CLASS="Ueberschrift-2">
<A NAME="pgfId-8301"></A>&nbsp;</H3>
<DIV>
<H4 CLASS="Ueberschrift-1IVZ">
<A NAME="pgfId-10745"></A><A HREF="tutorial.html#pgfId-7444" CLASS="Index">Table of contents</A></H4>
<P CLASS="Ueberschrift-2IVZ">
<A NAME="pgfId-10747"></A><A HREF="tutorial.html#pgfId-8301" CLASS="Index">	3	</A></P>
</DIV>
<DIV>
<H4 CLASS="Ueberschrift-1IVZ">
<A NAME="pgfId-10749"></A><A HREF="tutorial.html#pgfId-997291" CLASS="Index">Installation</A></H4>
<P CLASS="Ueberschrift-2IVZ">
<A NAME="pgfId-10751"></A><A HREF="tutorial.html#pgfId-997292" CLASS="Index">	5	Prerequisites</A></P>
<P CLASS="Ueberschrift-2IVZ">
<A NAME="pgfId-10753"></A><A HREF="tutorial.html#pgfId-997299" CLASS="Index">	5	Installation procedure</A></P>
</DIV>
<DIV>
<H4 CLASS="Ueberschrift-1IVZ">
<A NAME="pgfId-10755"></A><A HREF="tutorial.html#pgfId-997290" CLASS="Index">Introduction</A></H4>
<P CLASS="Ueberschrift-2IVZ">
<A NAME="pgfId-10757"></A><A HREF="tutorial.html#pgfId-997263" CLASS="Index">	8	Template file</A></P>
<P CLASS="Ueberschrift-2IVZ">
<A NAME="pgfId-10759"></A><A HREF="tutorial.html#pgfId-997280" CLASS="Index">	9	Preprocessor</A></P>
<P CLASS="Ueberschrift-2IVZ">
<A NAME="pgfId-10761"></A><A HREF="tutorial.html#pgfId-997312" CLASS="Index">	9	Template control script</A></P>
<P CLASS="Ueberschrift-2IVZ">
<A NAME="pgfId-10763"></A><A HREF="tutorial.html#pgfId-998272" CLASS="Index">	10	The output produced by the control script</A></P>
</DIV>
<DIV>
<H4 CLASS="Ueberschrift-1IVZ">
<A NAME="pgfId-10765"></A><A HREF="tutorial.html#pgfId-997266" CLASS="Index">The preprocessor and the </A><EM CLASS="Kap-">
PhpTempt</EM>
 class</H4>
<P CLASS="Ueberschrift-2IVZ">
<A NAME="pgfId-10767"></A><A HREF="tutorial.html#pgfId-997359" CLASS="Index">	11	General Syntax</A></P>
<P CLASS="Ueberschrift-2IVZ">
<A NAME="pgfId-10769"></A><A HREF="tutorial.html#pgfId-997408" CLASS="Index">	12	Usage examples</A></P>
<P CLASS="Ueberschrift-2IVZ">
<A NAME="pgfId-10771"></A><A HREF="tutorial.html#pgfId-997515" CLASS="Index">	13	Including the generated PHP files</A></P>
<P CLASS="Ueberschrift-2IVZ">
<A NAME="pgfId-10773"></A><A HREF="tutorial.html#pgfId-997566" CLASS="Index">	13	Including the generated Java files</A></P>
</DIV>
<DIV>
<H4 CLASS="Ueberschrift-1IVZ">
<A NAME="pgfId-10775"></A><A HREF="tutorial.html#pgfId-997263" CLASS="Index">Placeholders</A></H4>
<P CLASS="Ueberschrift-2IVZ">
<A NAME="pgfId-10777"></A><A HREF="tutorial.html#pgfId-997264" CLASS="Index">	15	Filling in values into placeholders</A></P>
<P CLASS="Ueberschrift-2IVZ">
<A NAME="pgfId-10779"></A><A HREF="tutorial.html#pgfId-997427" CLASS="Index">	17	Two ways of defining placeholders in templates</A></P>
</DIV>
<DIV>
<H4 CLASS="Ueberschrift-1IVZ">
<A NAME="pgfId-10781"></A><A HREF="tutorial.html#pgfId-997263" CLASS="Index">Repeating blocks</A></H4>
<P CLASS="Ueberschrift-2IVZ">
<A NAME="pgfId-10783"></A><A HREF="tutorial.html#pgfId-997264" CLASS="Index">	19	Syntax</A></P>
<P CLASS="Ueberschrift-2IVZ">
<A NAME="pgfId-10785"></A><A HREF="tutorial.html#pgfId-997266" CLASS="Index">	21	Alternative blocks</A></P>
<P CLASS="Ueberschrift-2IVZ">
<A NAME="pgfId-10787"></A><A HREF="tutorial.html#pgfId-997270" CLASS="Index">	22	Nested blocks</A></P>
<P CLASS="Ueberschrift-2IVZ">
<A NAME="pgfId-10789"></A><A HREF="tutorial.html#pgfId-997341" CLASS="Index">	24	The document root block</A></P>
<P CLASS="Ueberschrift-2IVZ">
<A NAME="pgfId-10791"></A><A HREF="tutorial.html#pgfId-1007139" CLASS="Index">	24	Comments</A></P>
<P CLASS="Ueberschrift-2IVZ">
<A NAME="pgfId-10793"></A><A HREF="tutorial.html#pgfId-1007310" CLASS="Index">	25	The rules for repeating blocks</A></P>
</DIV>
<DIV>
<H4 CLASS="Ueberschrift-1IVZ">
<A NAME="pgfId-10795"></A><A HREF="tutorial.html#pgfId-999030" CLASS="Index">Conditional blocks</A></H4>
<P CLASS="Ueberschrift-2IVZ">
<A NAME="pgfId-10797"></A><A HREF="tutorial.html#pgfId-1003277" CLASS="Index">	27	Syntax</A></P>
<P CLASS="Ueberschrift-2IVZ">
<A NAME="pgfId-10799"></A><A HREF="tutorial.html#pgfId-1003504" CLASS="Index">	28	A simple example using the cond tag</A></P>
<P CLASS="Ueberschrift-2IVZ">
<A NAME="pgfId-10801"></A><A HREF="tutorial.html#pgfId-1003742" CLASS="Index">	29	A simple example using the check tag</A></P>
</DIV>
<DIV>
<H4 CLASS="Ueberschrift-1IVZ">
<A NAME="pgfId-10803"></A><A HREF="tutorial.html#pgfId-999209" CLASS="Index">References to placeholders</A></H4>
<P CLASS="Ueberschrift-2IVZ">
<A NAME="pgfId-10805"></A><A HREF="tutorial.html#pgfId-1000282" CLASS="Index">	33	Syntax</A></P>
<P CLASS="Ueberschrift-2IVZ">
<A NAME="pgfId-10807"></A><A HREF="tutorial.html#pgfId-1000305" CLASS="Index">	34	Usage of fully qualified placeholders</A></P>
<P CLASS="Ueberschrift-2IVZ">
<A NAME="pgfId-10809"></A><A HREF="tutorial.html#pgfId-999206" CLASS="Index">	36	References to the parent block</A></P>
<P CLASS="Ueberschrift-2IVZ">
<A NAME="pgfId-10811"></A><A HREF="tutorial.html#pgfId-1000334" CLASS="Index">	39	Another example for the use of the </A><EM CLASS="Kursiv">
check</EM>
 tag</P>
</DIV>
<DIV>
<H4 CLASS="Ueberschrift-1IVZ">
<A NAME="pgfId-10813"></A><A HREF="tutorial.html#pgfId-1004161" CLASS="Index">Recursion</A></H4>
<P CLASS="Ueberschrift-2IVZ">
<A NAME="pgfId-10815"></A><A HREF="tutorial.html#pgfId-1004370" CLASS="Index">	41	Syntax</A></P>
<P CLASS="Ueberschrift-2IVZ">
<A NAME="pgfId-10817"></A><A HREF="tutorial.html#pgfId-1004400" CLASS="Index">	41	Depth-first traversal</A></P>
<P CLASS="Ueberschrift-2IVZ">
<A NAME="pgfId-10819"></A><A HREF="tutorial.html#pgfId-1005095" CLASS="Index">	44	Sorting entries example</A></P>
<P CLASS="Ueberschrift-2IVZ">
<A NAME="pgfId-10821"></A><A HREF="tutorial.html#pgfId-1005099" CLASS="Index">	46	Unrolling recursion</A></P>
<P CLASS="Ueberschrift-2IVZ">
<A NAME="pgfId-10823"></A><A HREF="tutorial.html#pgfId-1005643" CLASS="Index">	48	Restrictions on recursion</A></P>
<P CLASS="Ueberschrift-2IVZ">
<A NAME="pgfId-10825"></A><A HREF="tutorial.html#pgfId-1012178" CLASS="Index">	49	Relative paths in recursive templates</A></P>
</DIV>
<DIV>
<H4 CLASS="Ueberschrift-1IVZ">
<A NAME="pgfId-10827"></A><A HREF="tutorial.html#pgfId-997260" CLASS="Index">Known Bugs and missing Features</A></H4>
<P CLASS="Ueberschrift-2IVZ">
<A NAME="pgfId-10829"></A><A HREF="tutorial.html#pgfId-997305" CLASS="Index">	53	Features</A></P>
<P CLASS="Ueberschrift-2IVZ">
<A NAME="pgfId-10831"></A><A HREF="tutorial.html#pgfId-997304" CLASS="Index">	54	Known Bugs</A></P>
</DIV>
</DIV>
</DIV>
<DIV>
<H2 CLASS="Ueberschrift-1">
<A NAME="pgfId-997291"></A><A NAME="18169"></A>Installation</H2>
<DIV>
<H3 CLASS="Ueberschrift-2">
<A NAME="pgfId-997292"></A>Prerequisites</H3>
<P CLASS="Haupttext">
<A NAME="pgfId-997301"></A>In order to use <EM CLASS="Kap-">
PhpTempt</EM>
, the following programs need to be installed on your system:</P>
<UL>
<LI CLASS="Markiert">
<A NAME="pgfId-997305"></A>PHP 4.0.4pl1</LI>
<LI CLASS="Markiert">
<A NAME="pgfId-997306"></A>Java 1.1</LI>
</UL>
<P CLASS="Haupttext">
<A NAME="pgfId-1001176"></A>Additionally, if you configered PHP to run as a module of the Apache web server you must dispose of the following:</P>
<UL>
<LI CLASS="Markiert">
<A NAME="pgfId-997309"></A>Apache 1.3.19</LI>
</UL>
</DIV>
<DIV>
<H3 CLASS="Ueberschrift-2">
<A NAME="pgfId-997299"></A><A NAME="25534"></A>Installation procedure</H3>
<P CLASS="Haupttext">
<A NAME="pgfId-997300"></A>The installation procedure is as follows:</P>
<OL>
<LI CLASS="Numeriert-1">
<A NAME="pgfId-997443"></A>Copy the zipped tar file <EM CLASS="Kursiv">
</EM>
<EM CLASS="Kap-">
PhpTempt</EM>
<EM CLASS="Kursiv">
-xx.tar.gz</EM>
 to a directory of your choice, where <EM CLASS="Kursiv">
xx</EM>
 is a synonym for the current number of <EM CLASS="Kap-">
PhpTempt</EM>
. The directory you chose will be referred to as <EM CLASS="Kap-">
PhpTempt</EM>
 root from now on.</LI>
<LI CLASS="Numeriert">
<A NAME="pgfId-997511"></A>Change to the <EM CLASS="Kap-">
PhpTempt</EM>
 root directory. Unpack the zipped tar file by entering the command</LI>
</OL>
<P CLASS="Programm-einzeilig">
<A NAME="pgfId-997518"></A>	tar xzf <EM CLASS="Kap-">
PhpTempt</EM>
-xx.tar.gz</P>
<P CLASS="Eingerueckt">
<A NAME="pgfId-1001207"></A>This creates the <EM CLASS="Kap-">
PhpTempt</EM>
 directory that contains the runtime system (PHP programs and Java class files), and a subdirectory <EM CLASS="Kursiv">
parser</EM>
 that contains the preprocessor to convert templates to includable files.</P>
<OL>
<LI CLASS="Numeriert">
<A NAME="pgfId-997538"></A>Under linux create an alias <EM CLASS="Kursiv">
tpl</EM>
 defined as (C-Shell)</LI>
</OL>
<P CLASS="Programm-einzeilig">
<A NAME="pgfId-997556"></A>alias tpl 'java -cp &lt;<EM CLASS="Kap-">
PhpTempt</EM>
-root&gt;/parser PhpTemptParser'</P>
<P CLASS="Eingerueckt">
<A NAME="pgfId-997566"></A>Under Windows you may want to copy the file <EM CLASS="Kursiv">
tpl.bat</EM>
 into a directory that is listed in the <EM CLASS="Kursiv">
PATH</EM>
 environment variable. Load the batch file into an editor and change the first entry of the file,</P>
<P CLASS="Programm-einzeilig">
<A NAME="pgfId-997570"></A>	set <EM CLASS="Kap-">
PhpTempt</EM>
ROOT=&lt;<EM CLASS="Kap-">
PhpTempt</EM>
-root&gt;</P>
<P CLASS="Eingerueckt">
<A NAME="pgfId-997580"></A>to the name of the directory where you installed <EM CLASS="Kap-">
PhpTempt</EM>
.</P>
<OL>
<LI CLASS="Numeriert">
<A NAME="pgfId-997587"></A>Load the configuration file <EM CLASS="Kursiv">
php.ini</EM>
 into an editor and add the <EM CLASS="Kap-">
PhpTempt</EM>
 root directory to the list of directories defined by the variable <EM CLASS="Kursiv">
include_path</EM>
. Don't forget to restart the Apache Webserver if you included PHP as a module.</LI>
<LI CLASS="Numeriert">
<A NAME="pgfId-1001220"></A>Finally, copy the java-doc subdirectory containing the documentation of the <EM CLASS="Kap-">
PhpTempt</EM>
 Java classes into a directory that is accessible by your HTML-browser.</LI>
</OL>
</DIV>
</DIV>
<DIV>
<H2 CLASS="Ueberschrift-1">
<A NAME="pgfId-997290"></A>Introduction</H2>
<P CLASS="Haupttext">
<A NAME="pgfId-1002006"></A>Originally, <EM CLASS="Kap-">
PhpTempt</EM>
 was created to separate HTML output from processing code in a PHP program.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1005303"></A>Each page produced with <EM CLASS="Kap-">
PhpTempt</EM>
 consisted of at least two files: a precompiled template file and a PHP control script that read the template, added values to it at some places specified by the programmer and produced pure HTML output.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1005308"></A>Since version 24 <EM CLASS="Kap-">
PhpTempt</EM>
 can also be included into Java programs in order to simplify the creation of Java servlets or code generators of any kind.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1005342"></A>A huge portion of this tutorial has been written for the original PHP version but does equally apply to the Java version since the names and usage of the <EM CLASS="Kap-">
PhpTempt</EM>
 methods are identical for both. Where necessary, the user will be notified by any difference between the two versions.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1002050"></A>Generally speaking, the <EM CLASS="Kap-">
PhpTempt</EM>
 tool comprises a template preprocessor and a suite of classes to control the output of the template. The programmer uses only a few methods of the main class which is called <EM CLASS="Kursiv">
phptempt</EM>
 (<EM CLASS="Kursiv">
Phptempt</EM>
 in the Java version) . Most of the work will be done &quot;behind the scenes&quot;.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-997262"></A>It is best to introduce <EM CLASS="Kap-">
PhpTempt</EM>
 by means of a simple example.<A HREF="#pgfId-999282" CLASS="footnote">1</A></P>
<P CLASS="Haupttext">
<A NAME="pgfId-1002076"></A>Note: This tutorial assumes that you are a more or less experienced PHP programmer. Some examples assume that you are also familiar with the Java programming language.</P>
<DIV>
<IMG SRC="tutorial-1.gif">
</DIV>
<DIV>
<H3 CLASS="Ueberschrift-2">
<A NAME="pgfId-997263"></A>Template file</H3>
<P CLASS="Haupttext">
<A NAME="pgfId-997264"></A>The template file is essentially an ordinary HTML (or text) file augmented with special tags to denote placeholders or repeating blocks. Consider the following template in a file named <EM CLASS="Kursiv">
table.tpl</EM>
:</P>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-1001118"></A><A NAME="22612"></A>table template file</H5>
<P CLASS="Programm">
<A NAME="pgfId-1001149"></A>&lt;html&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001182"></A>&lt;head&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001183"></A>&lt;title&gt;{WINDOWTITLE}&lt;/title&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001184"></A>&lt;/head&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001185"></A>&lt;body&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001186"></A>&lt;table width='100%' border='1'&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001187"></A>	&lt;!--$ begin table1 --&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001188"></A>		&lt;tr bgcolor='#e0e0e0'&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001189"></A>			&lt;td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001190"></A>				&lt;!--$ var NUMBER--&gt;&lt;b&gt;1&lt;/b&gt;&lt;!--$ end NUMBER--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001191"></A>			&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001192"></A>			&lt;td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001193"></A>				&lt;!--$ var NAME--&gt;&lt;b&gt;a name&lt;/b&gt;&lt;!--$ end NAME--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001194"></A>			&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001195"></A>		&lt;/tr&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001196"></A>	&lt;!--$ alt table2 --&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001197"></A>		&lt;tr bgcolor='#909090'&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001198"></A>			&lt;td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001199"></A>				&lt;!--$ var NUMBER--&gt;&lt;b&gt;1&lt;!--$ end NUMBER--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001200"></A>			&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001201"></A>			&lt;td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001202"></A>				&lt;!--$ var NAME--&gt;&lt;b&gt;another name&lt;!--$ end NAME--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001203"></A>			&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001204"></A>		&lt;/tr&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001205"></A>	&lt;!--$ end table1 --&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001206"></A>&lt;table&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001207"></A>&lt;/body&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001208"></A>&lt;/html&gt;</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1001150"></A>Since browsers like Netscape Navigator or Internet Explorer interpret as comments the tags used by <EM CLASS="Kap-">
PhpTempt</EM>
, you can view the template files with these browsers:</P>
<OL>
<LI CLASS="Bildunterschrift">
<A NAME="pgfId-1000125"></A>The template file viewed with Internet Explorer</LI>
<IMG SRC="tutorial-2.gif" ALIGN="RIGHT">
</OL>
<P CLASS="Haupttext">
<A NAME="pgfId-1000132"></A>This is in fact one of the major benefits of <EM CLASS="Kap-">
PhpTempt</EM>
: with its concept of nested repeating blocks delimited by comment tags, it can be used with any HTML browser and WYSIWYG HTML editor.</P>
</DIV>
</DIV>
<DIV>
<H3 CLASS="Ueberschrift-2">
<A NAME="pgfId-997280"></A>Preprocessor</H3>
<P CLASS="Haupttext">
<A NAME="pgfId-998210"></A>A preprocessor will create PHP code which you include into the PHP control script. The preprocessor is a Java application and is executed with the following DOS or UNIX command</P>
<P CLASS="Programm-einzeilig">
<A NAME="pgfId-997289"></A>	tpl table.tpl</P>
<P CLASS="Haupttext">
<A NAME="pgfId-997299"></A>provided the <EM CLASS="Kap-">
PhpTempt</EM>
 package has been installed properly (<A HREF="tutorial.html#25534" CLASS="XRef">See Installation procedure</A>). You should not bother with the contents of the files that the template preprocessor generates - a sequence of definitions of hashes that reflect the structure of the template file. </P>
</DIV>
<DIV>
<H3 CLASS="Ueberschrift-2">
<A NAME="pgfId-997312"></A>Template control script</H3>
<P CLASS="Haupttext">
<A NAME="pgfId-998215"></A>The PHP script that will add content to the template and will produce pure HTML output is shown below:</P>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-997313"></A>PHP control script</H5>
<P CLASS="Programm">
<A NAME="pgfId-1000925"></A>&lt;?php</P>
<P CLASS="Programm">
<A NAME="pgfId-1001221"></A>	include (`phptempt.php');</P>
<P CLASS="Programm">
<A NAME="pgfId-1001222"></A>	$t = new phptempt (`table.inc');</P>
<P CLASS="Programm">
<A NAME="pgfId-1001223"></A>&nbsp;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001224"></A>	// define an array of names for the sample table:</P>
<P CLASS="Programm">
<A NAME="pgfId-1001225"></A>	$names = array (`hans', `dennis', `matthias', `benjamin', `muriel');</P>
<P CLASS="Programm">
<A NAME="pgfId-1001226"></A>&nbsp;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001227"></A>	$t-&gt;addVal (`WINDOWTITLE', `Table Template');</P>
<P CLASS="Programm">
<A NAME="pgfId-1001228"></A>&nbsp;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001229"></A>	// in a loop, set the NAME and NUMBER placeholders for the</P>
<P CLASS="Programm">
<A NAME="pgfId-1001230"></A>	// subsequent tables; switch between table1 and table2:</P>
<P CLASS="Programm">
<A NAME="pgfId-1001231"></A>	for ($i=0; $i&lt;sizeof($names); $i++) {</P>
<P CLASS="Programm">
<A NAME="pgfId-1001232"></A>		if ($i % 2 == 0) {</P>
<P CLASS="Programm">
<A NAME="pgfId-1001233"></A>			$t-&gt;begin (`table1');</P>
<P CLASS="Programm">
<A NAME="pgfId-1001234"></A>			$t-&gt;addVal (`NUMBER', $i);</P>
<P CLASS="Programm">
<A NAME="pgfId-1001235"></A>			$t-&gt;addVal (`NAME', $names[$i]);</P>
<P CLASS="Programm">
<A NAME="pgfId-1001236"></A>			$t-&gt;end (`table1');</P>
<P CLASS="Programm">
<A NAME="pgfId-1001237"></A>		}</P>
<P CLASS="Programm">
<A NAME="pgfId-1001238"></A>		else {</P>
<P CLASS="Programm">
<A NAME="pgfId-1001239"></A>			$t-&gt;begin (`table2');</P>
<P CLASS="Programm">
<A NAME="pgfId-1001240"></A>			$t-&gt;addVal (`NUMBER', $i);</P>
<P CLASS="Programm">
<A NAME="pgfId-1001241"></A>			$t-&gt;addVal (`NAME', $names[$i]);</P>
<P CLASS="Programm">
<A NAME="pgfId-1001242"></A>			$t-&gt;end (`table2');</P>
<P CLASS="Programm">
<A NAME="pgfId-1001243"></A>		}</P>
<P CLASS="Programm">
<A NAME="pgfId-1001244"></A>	}</P>
<P CLASS="Programm">
<A NAME="pgfId-1001245"></A>	$t-&gt;out();</P>
<P CLASS="Programm">
<A NAME="pgfId-1001246"></A>?&gt;</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1000892"></A>The <EM CLASS="Kap-">
PhpTempt</EM>
 class is included in the first line of the script. The class is instantiated in the second line. Subsequent lines fill in values for the placeholders defined in the template file. The last line of the control script completes the script and prints the pure HTML code for the requested page.</P>
</DIV>
</DIV>
<DIV>
<H3 CLASS="Ueberschrift-2">
<A NAME="pgfId-998272"></A>The output produced by the control script</H3>
<P CLASS="Haupttext">
<A NAME="pgfId-998277"></A>Below you can see the resulting output with Internet explorer:</P>
<OL>
<LI CLASS="Bildunterschrift">
<A NAME="pgfId-998108"></A><A NAME="66465"></A>Output resulting from a request of the control script</LI>
<IMG SRC="tutorial-3.gif" ALIGN="RIGHT">
</OL>
<P CLASS="Bild-in-Absatz">
<A NAME="pgfId-998265"></A>We will now discuss the capabilities of <EM CLASS="Kap-">
PhpTempt</EM>
 in more detail.</P>
</DIV>
</DIV>
<DIV>
<H2 CLASS="Ueberschrift-1">
<A NAME="pgfId-997266"></A><A NAME="85697"></A>The preprocessor and the <EM CLASS="Kap-">
PhpTempt</EM>
 class</H2>
<DIV>
<H3 CLASS="Ueberschrift-2">
<A NAME="pgfId-997359"></A>General Syntax</H3>
<P CLASS="Haupttext">
<A NAME="pgfId-1002177"></A>The <EM CLASS="Kursiv">
preprocessor</EM>
 (otherwise called <EM CLASS="Kursiv">
template parser</EM>
) is a command line tool written in Java that can be used on either Windows or Linux/Unix, provided that a Java Runtime Environment is installed on the system.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1002184"></A>Executing the preprocessor without command line parameters causes it to print a list of option:<A HREF="#pgfId-1002180" CLASS="footnote">2</A></P>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-1002195"></A>Usage information printed by the preprocessor</H5>
<P CLASS="Programm">
<A NAME="pgfId-1002216"></A>Usage:</P>
<P CLASS="Programm">
<A NAME="pgfId-1002217"></A>java PhpTemptParser [ options ] file1 file2 ...</P>
<P CLASS="Programm">
<A NAME="pgfId-1002218"></A>    file1 file2 ...</P>
<P CLASS="Programm">
<A NAME="pgfId-1002219"></A>        One or more template files.</P>
<P CLASS="Programm">
<A NAME="pgfId-1002220"></A>and options is one or more of the following:</P>
<P CLASS="Programm">
<A NAME="pgfId-1002221"></A>	-s&lt;suffix&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1002222"></A>		Adds a &lt;suffix&gt; to each file (after removing the original file<BR>
		suffixes).</P>
<P CLASS="Programm">
<A NAME="pgfId-1002223"></A>		The default suffix is &quot;inc&quot;. Please do not specify a dot with the<BR>
		suffix.</P>
<P CLASS="Programm">
<A NAME="pgfId-1002224"></A>	-d &lt;targetDir&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1002225"></A>		Sets the target directory where to write the generated file(s)<BR>
		to &lt;targetDir&gt;.</P>
<P CLASS="Programm">
<A NAME="pgfId-1002226"></A>		The default is to put the generated files into the directories of<BR>
		the template files.</P>
<P CLASS="Programm">
<A NAME="pgfId-1002228"></A>	-j</P>
<P CLASS="Programm">
<A NAME="pgfId-1002229"></A>		Creates Java code in a file with suffix java and _&lt;suffix&gt;<BR>
		added to the filename, where &lt;suffix&gt; is as specified by the<BR>
		-s option.</P>
<P CLASS="Programm">
<A NAME="pgfId-1002691"></A>	-jp &lt;container-package&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1002692"></A>		Specify a Java &lt;container-package&gt; for the generated Java<BR>
		class (only valid in connection with the -j-option).</P>
<P CLASS="Programm">
<A NAME="pgfId-1002231"></A>    -D</P>
<P CLASS="Programm">
<A NAME="pgfId-1002232"></A>		Enters debug mode, where additional PHP code is included<BR>
		in the generated files.</P>
<P CLASS="Programm">
<A NAME="pgfId-1002234"></A>	-b</P>
<P CLASS="Programm">
<A NAME="pgfId-1002235"></A>		Do not URL-encode the pure block contents. Escape<BR>
		sequences will be interpreted as byte values, e.g. %0D as car<BR>
		return. This is useful for the creation of binary files. Please<BR>
		avoid using whitespaces (car return, line feed, etc). The</P>
<P CLASS="Programm">
<A NAME="pgfId-1002282"></A>		parser will issue warnings if it encounters whitespaces in pure<BR>
		blocks with this option.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-997400"></A>If the -d option is supplied, <EM CLASS="Kursiv">
target-dir</EM>
 specifies the directory where to save the includable files generated from the template. The default action will save the generated file to the same directory as the original template.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-997401"></A>If the -s option is supplied then <EM CLASS="Kursiv">
suffix</EM>
 specifies the suffix to be appended to the name of each generated file. The default suffix is <EM CLASS="Kursiv">
inc</EM>
.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-999494"></A>The -D option sets the debug flag for the preprocessor. If the debug flag is set then the names of the blocks and placeholders can be queried from within the methods of the <EM CLASS="Kursiv">
phptempt.php </EM>
file. This option merly serves debugging purposes.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1002301"></A>The -j option creates a Java source file instead of a PHP include file. This option is extremely useful for code generators written in Java or to create Java servlets. An additional argument -jp that is only valid in conjunction with the Java source creation, tells <EM CLASS="Kap-">
PhpTempt</EM>
 to add a package declaration to the generated Java source.</P>
</DIV>
</DIV>
<DIV>
<H3 CLASS="Ueberschrift-2">
<A NAME="pgfId-997408"></A>Usage examples</H3>
<P CLASS="Haupttext">
<A NAME="pgfId-997412"></A>The command line </P>
<P CLASS="Programm-einzeilig">
<A NAME="pgfId-997413"></A>	tpl table.tpl</P>
<P CLASS="Haupttext">
<A NAME="pgfId-997443"></A>converts the file <EM CLASS="Kursiv">
table.tpl</EM>
 in the current directory to an includable file <EM CLASS="Kursiv">
table.inc</EM>
 in the current directory. The same file is converted to a Java source file <EM CLASS="Kursiv">
table_inc.java</EM>
 with the command</P>
<P CLASS="Programm-einzeilig">
<A NAME="pgfId-1002326"></A>	tpl table.tpl -j</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1002373"></A>The Java class files to import by a program using <EM CLASS="Kap-">
PhpTempt</EM>
 can be found in the <EM CLASS="Kursiv">
java-src</EM>
 subdirectory of the distribution. Examples of the use of this class can be found in the <EM CLASS="Kursiv">
java-examples</EM>
 subdirectory. Finally, a <EM CLASS="Kursiv">
javadoc</EM>
 documentation of the classes is available in the <EM CLASS="Kursiv">
java-doc</EM>
 subdirectory.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1002327"></A>The command</P>
<P CLASS="Programm-einzeilig">
<A NAME="pgfId-1002331"></A>	tpl e:&#92;<EM CLASS="Kap-">
PhpTempt</EM>
&#92;Templates&#92;table.tpl</P>
<P CLASS="Haupttext">
<A NAME="pgfId-997448"></A>converts the file <EM CLASS="Kursiv">
table.tpl</EM>
 that is located in the folder <EM CLASS="Kursiv">
e:&#92;</EM>
<EM CLASS="Kap-">
PhpTempt</EM>
<EM CLASS="Kursiv">
&#92;Templates</EM>
 and writes the generated file, <EM CLASS="Kursiv">
table.inc</EM>
 to that very same folder. The appropriate command on a linux system would be, for example:</P>
<P CLASS="Programm-einzeilig">
<A NAME="pgfId-997451"></A>	tpl /usr/local/projects/<EM CLASS="Kap-">
PhpTempt</EM>
/Templates/table.inc</P>
<P CLASS="Haupttext">
<A NAME="pgfId-997455"></A>Finally, a call</P>
<P CLASS="Programm-einzeilig">
<A NAME="pgfId-997486"></A>	tpl -d g:&#92;php-includes -s php table.tpl selection.tpl</P>
<P CLASS="Haupttext">
<A NAME="pgfId-997492"></A>would start conversion of the specified files, <EM CLASS="Kursiv">
table.tpl</EM>
 and <EM CLASS="Kursiv">
selection.tpl</EM>
, in the current working directory. The resulting files would be stored in the folder <EM CLASS="Kursiv">
g:&#92;php-includes</EM>
, the names of these files being <EM CLASS="Kursiv">
table.php</EM>
 and <EM CLASS="Kursiv">
selection.php</EM>
, respectively.</P>
</DIV>
<DIV>
<H3 CLASS="Ueberschrift-2">
<A NAME="pgfId-997515"></A>Including the generated PHP files</H3>
<P CLASS="Haupttext">
<A NAME="pgfId-997519"></A>To include the generated files into your PHP control scripts, simply include the <EM CLASS="Kap-">
PhpTempt</EM>
 class file and instantiate the <EM CLASS="Kap-">
PhpTempt</EM>
 class. For example, to include a generated file <EM CLASS="Kursiv">
table.inc</EM>
, add the following to your control script:</P>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-997539"></A>Including a generated PHP file</H5>
<P CLASS="Programm">
<A NAME="pgfId-997526"></A>&lt;?php</P>
<P CLASS="Programm">
<A NAME="pgfId-997545"></A>include (&quot;phptempt.php&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-997549"></A>$t = new phptempt (&quot;table.inc&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-997555"></A>// more PHP code to follow</P>
<P CLASS="Programm">
<A NAME="pgfId-997562"></A>// ...</P>
<P CLASS="Programm">
<A NAME="pgfId-997556"></A>?&gt;</P>
</DIV>
</DIV>
<DIV>
<H3 CLASS="Ueberschrift-2">
<A NAME="pgfId-997566"></A>Including the generated Java files</H3>
<P CLASS="Haupttext">
<A NAME="pgfId-1002123"></A>To include the generated file into your Java control program, simply import the <EM CLASS="Kap-">
PhpTempt</EM>
 class in package phptempt and instantiate the Phptempt class (note the capital letter &quot;P&quot; at the beginning of the class name in contrast to the class name of the <EM CLASS="Kap-">
PhpTempt</EM>
 class for PHP).</P>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-1002076"></A>Including a generated Java file</H5>
<P CLASS="Programm">
<A NAME="pgfId-1002087"></A>import phptempt.*;</P>
<P CLASS="Programm">
<A NAME="pgfId-1002089"></A>public class table {</P>
<P CLASS="Programm">
<A NAME="pgfId-1002091"></A>	public static void main (String[] args) {</P>
<P CLASS="Programm">
<A NAME="pgfId-1002093"></A>		Phptempt t = new Phptempt (&quot;table_inc&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1002095"></A>	// more Java code to follow</P>
<P CLASS="Programm">
<A NAME="pgfId-1002345"></A>}</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1002748"></A>In order to be able to compile a generated Java file, you must specify the <EM CLASS="Kap-">
PhpTempt</EM>
 path with the <EM CLASS="Kursiv">
classpath</EM>
 option. For the above example this is:</P>
<P CLASS="Programm-einzeilig">
<A NAME="pgfId-1002166"></A>javac -classpath /usr/local/phptempt/java-src table_inc.java</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1002403"></A>where in this example <EM CLASS="Kursiv">
/usr/local/phptempt</EM>
 is the <EM CLASS="Kap-">
PhpTempt</EM>
 root directory.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1002787"></A>Note that, when using the -jp option, you have to specify the fully qualified class name (ie. package and class name, separated by dots) in the constructor call to the <EM CLASS="Kap-">
PhpTempt</EM>
 class. Thus, for example, to compile a template <EM CLASS="Kursiv">
table.tpl</EM>
 that belongs to package <EM CLASS="Kursiv">
tree.java</EM>
, run the following commands:</P>
<P CLASS="Programm-einzeilig">
<A NAME="pgfId-1002817"></A>tpl -j -jp &quot;tree.java&quot; tree/java/table.tpl<BR>
javac -sourcepath .:/usr/local/phptempt/java-src tree/java/table.php</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1002818"></A>where the invocation of the constructor would be:</P>
<P CLASS="Programm-einzeilig">
<A NAME="pgfId-1002807"></A>	Phptempt t = new Phptempt (&quot;tree.java.table_inc&quot;);</P>
</DIV>
</DIV>
</DIV>
<DIV>
<H2 CLASS="Ueberschrift-1">
<A NAME="pgfId-997263"></A>Placeholders</H2>
<DIV>
<H3 CLASS="Ueberschrift-2">
<A NAME="pgfId-997264"></A>Filling in values into placeholders</H3>
<P CLASS="Haupttext">
<A NAME="pgfId-997265"></A>The following simple example of a PHP template, <EM CLASS="Kursiv">
simple.tpl</EM>
, shall be used in an address book:</P>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-997348"></A><A NAME="62544"></A><BR>
Placeholders in a template file</H5>
<P CLASS="Programm">
<A NAME="pgfId-1000823"></A>&lt;html&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000927"></A>&lt;head&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000928"></A>&lt;title&gt;Placeholder example&lt;/title&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000929"></A>&lt;/head&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000930"></A>&lt;body&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000931"></A>Your name is {NAME}. You live at {STREET} in {TOWN}. &lt;br&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000932"></A>Your job: {DESCRIPT}</P>
<P CLASS="Programm">
<A NAME="pgfId-1000933"></A>&lt;/body&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000934"></A>&lt;/html&gt;</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1000805"></A>There are three placeholders within this template file: NAME, STREET and TOWN.When defining the HTML template, you do not know where to get concrete values for these placeholders, but you do know about their concrete semantics (as the names of the placeholders suggest) and their position within the resulting HTML file.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-997395"></A>Change to the folder in which the template resides and create an includable, <EM CLASS="Kursiv">
simple.inc</EM>
, by typing:</P>
<P CLASS="Programm-einzeilig">
<A NAME="pgfId-997396"></A>	tpl simple.tpl</P>
<P CLASS="Haupttext">
<A NAME="pgfId-997850"></A>at the prompt of your favorite shell (<A HREF="tutorial.html#85697" CLASS="XRef">See The preprocessor and the PhpTempt class</A>).</P>
<P CLASS="Haupttext">
<A NAME="pgfId-997397"></A>The following PHP control script will fill in values for the placeholders from a predefined array:</P>
</DIV>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-997364"></A><A NAME="77355"></A>PHP script to fill in values into placeholders</H5>
<P CLASS="Programm">
<A NAME="pgfId-1000866"></A>&lt;?php</P>
<P CLASS="Programm">
<A NAME="pgfId-1000954"></A>include (`phptempt.php');</P>
<P CLASS="Programm">
<A NAME="pgfId-1000955"></A>$t = new phptempt (`simple.inc');</P>
<P CLASS="Programm">
<A NAME="pgfId-1000956"></A>$a = array (`name' =&gt; `hans',</P>
<P CLASS="Programm">
<A NAME="pgfId-1000957"></A>	`street' =&gt; `some place', `town' =&gt; `Germany',</P>
<P CLASS="Programm">
<A NAME="pgfId-1000958"></A>	`what' =&gt; `Software Engineer, Programmer, Database Desinger');</P>
<P CLASS="Programm">
<A NAME="pgfId-1000959"></A>&nbsp;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000960"></A>$t-&gt;addVal (`NAME', $a[`name']);</P>
<P CLASS="Programm">
<A NAME="pgfId-1000961"></A>$t-&gt;addVal (`STREET', $a[`street']);</P>
<P CLASS="Programm">
<A NAME="pgfId-1000962"></A>$t-&gt;addVal (`TOWN', $a[`town']);</P>
<P CLASS="Programm">
<A NAME="pgfId-1000963"></A>$t-&gt;addVal (`DESCRIPT', $a[`what']);</P>
<P CLASS="Programm">
<A NAME="pgfId-1000964"></A>&nbsp;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000965"></A>$t-&gt;out ();</P>
<P CLASS="Programm">
<A NAME="pgfId-1000966"></A>?&gt;</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1000829"></A>If you request the PHP script in a browser, you will see the placeholders of the template file replaced by the concrete values that you filled in using method <EM CLASS="Kursiv">
addVal</EM>
 of the <EM CLASS="Kap-">
PhpTempt</EM>
 class.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-997402"></A>A step-by-step explanation of the example follows:</P>
<P CLASS="Haupttext">
<A NAME="pgfId-997403"></A>First, the <EM CLASS="Kap-">
PhpTempt</EM>
 class definitions are included to the control script and an instance of the <EM CLASS="Kap-">
PhpTempt</EM>
 class is created:</P>
<P CLASS="Programm-einzeilig">
<A NAME="pgfId-997416"></A>	include ('<EM CLASS="Kap-">
PhpTempt</EM>
.php');<BR>
	$t = new <EM CLASS="Kap-">
PhpTempt</EM>
 ('simple.inc');</P>
<P CLASS="Haupttext">
<A NAME="pgfId-997411"></A>Behind the scenes, a representation of the template file, created by the template parser in the first place, will be read by the instance.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-997426"></A>The next step is to start adding values to the template. For example, you replace <EM CLASS="Kursiv">
NAME</EM>
 with a concrete value, 'hans', by a call to method <EM CLASS="Kursiv">
addValue</EM>
:</P>
<P CLASS="Programm-einzeilig">
<A NAME="pgfId-997449"></A>	$t-&gt;addVal ('NAME', $a['name']);</P>
<P CLASS="Haupttext">
<A NAME="pgfId-997454"></A>To actually output the document with the placeholders replaced by the concrete values, you use the method <EM CLASS="Kursiv">
out</EM>
 in the manner depicted below:</P>
<P CLASS="Programm-einzeilig">
<A NAME="pgfId-997455"></A>	$t-&gt;out();</P>
</DIV>
</DIV>
<DIV>
<H3 CLASS="Ueberschrift-2">
<A NAME="pgfId-997427"></A>Two ways of defining placeholders in templates</H3>
<P CLASS="Haupttext">
<A NAME="pgfId-997267"></A>If you view the template file in a browser you might find how the placeholders destroy the perfect layout of the page in a somewhat annoying manner.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-997912"></A>Usually you want to insert a dummy text that will be replaced by the actual content of the page. Dummy text portions make it easier for the designer of the page and their users to estimate the impact of the design.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-997917"></A>Instead of adding placeholders in curly braces, in a <EM CLASS="Kap-">
PhpTempt</EM>
 template one can add dummy text associated with a placeholder. The template file from <A HREF="tutorial.html#62544" CLASS="XRef">See Placeholders in a template file</A> with dummy text instead of placeholders in curly braces is shown below:</P>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-997948"></A>Template file with dummy text</H5>
<P CLASS="Programm">
<A NAME="pgfId-1000897"></A>&lt;html&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001004"></A>&lt;head&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001005"></A>&lt;title&gt;Simple placeholder example (with dummy text)&lt;/title&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001006"></A>&lt;/head&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001007"></A>&lt;body&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001008"></A>Your name is &lt;!--$ var NAME--&gt;(a name)&lt;!--$ end--&gt;.</P>
<P CLASS="Programm">
<A NAME="pgfId-1001009"></A>You live at &lt;!--$ var STREET--&gt;(a street)&lt;!--$ end--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001010"></A>in &lt;!--$ var TOWN--&gt;(a town)&lt;!--$ end--&gt;.</P>
<P CLASS="Programm">
<A NAME="pgfId-1001011"></A>Your job:</P>
<P CLASS="Programm">
<A NAME="pgfId-1001012"></A>&lt;!--$ var DESCRIPT--&gt;(A short description of what You do)&lt;!--$ end--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001013"></A>&lt;/body&gt;</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1000880"></A>If you view the above template in a browser you will only see the following text:</P>
<P CLASS="Haupttext">
<A NAME="pgfId-997984"></A>&quot;Your name is (a name). You live at (a street) in (a town). Your job: (A short description of what you do)&quot;.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-997992"></A>In contrast the text produced by the very same control script (<A HREF="tutorial.html#77355" CLASS="XRef">See PHP script to fill in values into placeholders</A>) will look like this:</P>
<P CLASS="Haupttext">
<A NAME="pgfId-997999"></A>&quot;	Your name is hans. You live at some place in Germany. Your job: Software Engineer, Programmer, Database Designer&quot;.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-998033"></A>Note the somewhat strange fashion in which a <EM CLASS="Kap-">
PhpTempt</EM>
 tag is introduced. The use of &lt;!--$ to mark a <EM CLASS="Kap-">
PhpTempt</EM>
 tag simplifies the preprocessor a lot. At the same time, browsers interpret the &lt;!-- suffix of the tag as the beginning of a comment. This is the reason why you cannot, in general, see the <EM CLASS="Kap-">
PhpTempt</EM>
 tags when viewing a template file in a browser.<A HREF="#pgfId-998049" CLASS="footnote">3</A></P>
<P CLASS="Haupttext">
<A NAME="pgfId-998113"></A><EM CLASS="Kap-">
PhpTempt</EM>
 defines many different tags to control the behaviour of a template file:</P>
</DIV>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-999016"></A>Tags defined in <EM CLASS="Kap-">
PhpTempt</EM>
</H5>
<P CLASS="Programm-einzeilig">
<A NAME="pgfId-998119"></A>	alt<BR>
	begin<BR>
	check<BR>
	cond<BR>
	var<BR>
	rec<BR>
	ignore<BR>
	end</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1004025"></A>The <EM CLASS="Kursiv">
begin</EM>
 and <EM CLASS="Kursiv">
alt</EM>
 tags are used to define (alternative) repeating blocks and will be explained in the suite of this chapter (<A HREF="tutorial.html#75783" CLASS="XRef">See Repeating blocks</A>). The <EM CLASS="Kursiv">
var</EM>
 tag is used to introduce placeholders with dummy text. <EM CLASS="Kursiv">
check</EM>
 and <EM CLASS="Kursiv">
cond</EM>
 check for a specified placeholder or condition, respectively, to decide if the block must be printed or not. The <EM CLASS="Kursiv">
rec</EM>
 tag is used for recursion. The <EM CLASS="Kursiv">
ignore</EM>
 block will simply be skipped by the preprocessor (<A HREF="tutorial.html#78971" CLASS="XRef">See Comments</A>). Finally, the <EM CLASS="Kursiv">
end</EM>
 tag is used to close a block opened by one of the other tags.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-998153"></A>Note that the identifier of the block or placeholder in the <EM CLASS="Kursiv">
end</EM>
 tag is optional and can be omitted. If you choose to specify it, though (ie. if you are a <EM CLASS="Kursiv">
defensive</EM>
 programmer) the identifier in the <EM CLASS="Kursiv">
end</EM>
 tag and the identifier in the corresponding <EM CLASS="Kursiv">
begin</EM>
, <EM CLASS="Kursiv">
alt</EM>
 or <EM CLASS="Kursiv">
var</EM>
 tag must match. Otherwise the preprocessor will issue a warning.<A HREF="#pgfId-999026" CLASS="footnote">4</A></P>
</DIV>
</DIV>
</DIV>
<DIV>
<H2 CLASS="Ueberschrift-1">
<A NAME="pgfId-997263"></A><A NAME="75783"></A>Repeating blocks</H2>
<P CLASS="Haupttext">
<A NAME="pgfId-997401"></A>A repeating block in <EM CLASS="Kap-">
PhpTempt</EM>
 is a portion of a template file enclosed in <EM CLASS="Kursiv">
begin</EM>
 and <EM CLASS="Kursiv">
end</EM>
 tags that contains at least one placeholder or another (<EM CLASS="Kursiv">
nested</EM>
) repeating block. Their purpose is to repeat the contents (<EM CLASS="Kursiv">
body</EM>
) of the block and to print a different placeholder value in each of the repetitions.</P>
<DIV>
<H3 CLASS="Ueberschrift-2">
<A NAME="pgfId-997264"></A><A NAME="53111"></A>Syntax</H3>
<P CLASS="Haupttext">
<A NAME="pgfId-997265"></A>A repeating block, or <EM CLASS="Kursiv">
block</EM>
 for short, has the following general syntax (in EBNF-like notation):</P>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-998773"></A><A NAME="91159"></A>General syntax of repeating blocks</H5>
<P CLASS="Programm">
<A NAME="pgfId-997516"></A>	block ::=</P>
<P CLASS="Programm">
<A NAME="pgfId-999805"></A>		&quot;&lt;!--$&quot; &quot;begin&quot; blockident &quot;--&gt;&quot;</P>
<P CLASS="Programm">
<A NAME="pgfId-997533"></A>		body</P>
<P CLASS="Programm">
<A NAME="pgfId-999806"></A>		[ &quot;&lt;!--$&quot; &quot;alt&quot; blockident &quot;--&gt;&quot; body ]</P>
<P CLASS="Programm">
<A NAME="pgfId-997534"></A>		&quot;&lt;!--$&quot; &quot;end&quot; [ blockident ] &quot;--&gt;&quot;</P>
<P CLASS="Haupttext">
<A NAME="pgfId-997535"></A>Quotes enclose character tokens, everything within brackets is optional. Here <EM CLASS="Kursiv">
blockident</EM>
 and <EM CLASS="Kursiv">
body</EM>
 are nonterminals defined in an obvious way. The <EM CLASS="Kursiv">
alt</EM>
 tag signifies an alternative block and will be introduced later (<A HREF="tutorial.html#69420" CLASS="XRef">See Alternative blocks</A>).</P>
<P CLASS="Haupttext">
<A NAME="pgfId-999811"></A>To produce a list of addresses within a simple template that augments the address book entry template (<A HREF="tutorial.html#62544" CLASS="XRef">See Placeholders in a template file</A>), a block might be used in the manner depicted below:</P>
</DIV>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-997558"></A><A NAME="81964"></A>Template to produce a list of addresses</H5>
<P CLASS="Programm">
<A NAME="pgfId-1002377"></A>&lt;html&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003131"></A>&lt;head&gt;&lt;title&gt;Addresses in a block example&lt;/title&gt;&lt;/head&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003132"></A>&lt;body&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003133"></A>&lt;table border=&quot;1&quot;&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003134"></A>	&lt;tr&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003135"></A>		&lt;td colspan=&quot;3&quot;&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003136"></A>			&lt;b&gt;Addresses&lt;/b&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003137"></A>		&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003138"></A>	&lt;/tr&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003139"></A>	&lt;tr&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003140"></A>		&lt;td&gt;&lt;b&gt;name&lt;/b&gt;&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003141"></A>		&lt;td&gt;&lt;b&gt;street&lt;/b&gt;&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003142"></A>		&lt;td&gt;&lt;b&gt;town&lt;/b&gt;&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003143"></A>	&lt;/tr&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003144"></A>	&lt;!--$ <EM CLASS="Fett">
begin</EM>
 aBlock--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003145"></A>		&lt;tr&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003146"></A>			&lt;td&gt;&lt;!--$ var NAME--&gt;a name&lt;!--$ end--&gt;&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003147"></A>			&lt;td&gt;&lt;!--$ var STREET--&gt;a name&lt;!--$ end--&gt;&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003148"></A>			&lt;td&gt;&lt;!--$ var TOWN--&gt;a name&lt;!--$ end--&gt;&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003149"></A>		&lt;/tr&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003150"></A>		&lt;tr&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003151"></A>			&lt;td colspan=&quot;3&quot;&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003152"></A>				&lt;!--$ var DESCRIPT--&gt;This describes the person that</P>
<P CLASS="Programm">
<A NAME="pgfId-1003153"></A>					lives under the given address&lt;!--$ end--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003154"></A>			&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003155"></A>		&lt;/tr&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003156"></A>	&lt;!--$ <EM CLASS="Fett">
end</EM>
 aBlock--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003157"></A>&lt;/table&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003158"></A>&lt;/body&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003159"></A>&lt;/html&gt;</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1002329"></A>The <EM CLASS="Kursiv">
begin</EM>
 and <EM CLASS="Kursiv">
end</EM>
 tag for the singlemost block <EM CLASS="Kursiv">
aBlock</EM>
 in <A HREF="tutorial.html#81964" CLASS="XRef">See Template to produce a list of addresses</A> are in bold. 4 placeholders appear within the block. We will fill in values in a PHP control script for the placeholders several times in a stream-like manner. This time, though, we will insert a name, street, town and description of several people, as the PHP script below demonstrates.</P>
</DIV>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-997868"></A><A NAME="49359"></A>Filling in values into placeholders in a block</H5>
<P CLASS="Programm">
<A NAME="pgfId-1002433"></A>&lt;?php</P>
<P CLASS="Programm">
<A NAME="pgfId-1003161"></A>	$data['name'] = array ('hans', 'dennis', 'christine');</P>
<P CLASS="Programm">
<A NAME="pgfId-1003162"></A>	$data['street'] = array ('hechinger', 'NN', 'NN');</P>
<P CLASS="Programm">
<A NAME="pgfId-1003163"></A>	$data['town'] = array ('T&amp;uuml;bingen', 'Reutlingen', 'Paris');</P>
<P CLASS="Programm">
<A NAME="pgfId-1003164"></A>	$data['description'] = array (</P>
<P CLASS="Programm">
<A NAME="pgfId-1003165"></A>		'Software Engineer, Programmer, Database Designer',</P>
<P CLASS="Programm">
<A NAME="pgfId-1003166"></A>		'Programmierer, real computer nerd',</P>
<P CLASS="Programm">
<A NAME="pgfId-1003167"></A>		'Manager des affaires culturelles'</P>
<P CLASS="Programm">
<A NAME="pgfId-1003168"></A>	);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003169"></A>	include ('phptempt.php');</P>
<P CLASS="Programm">
<A NAME="pgfId-1003170"></A>	$t = new phptempt ('addresses.inc');</P>
<P CLASS="Programm">
<A NAME="pgfId-1003171"></A>	for ($i=0; $i&lt;sizeof($data['name']); $i++) {</P>
<P CLASS="Programm">
<A NAME="pgfId-1003172"></A>		$t-&gt;<EM CLASS="Fett">
begin</EM>
 ('aBlock');</P>
<P CLASS="Programm">
<A NAME="pgfId-1003173"></A>		$t-&gt;addVal ('NAME', $data['name'][$i]);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003174"></A>		$t-&gt;addVal ('STREET', $data['street'][$i]);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003175"></A>		$t-&gt;addVal ('TOWN', $data['town'][$i]);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003176"></A>		$t-&gt;addVal ('DESCRIPT', $data['description'][$i]);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003177"></A>		$t-&gt;<EM CLASS="Fett">
end</EM>
 ('aBlock');</P>
<P CLASS="Programm">
<A NAME="pgfId-1003178"></A>	}</P>
<P CLASS="Programm">
<A NAME="pgfId-1003179"></A>	$t-&gt;out ();</P>
<P CLASS="Programm">
<A NAME="pgfId-1003180"></A>?&gt;</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1002401"></A>In <A HREF="tutorial.html#49359" CLASS="XRef">See Filling in values into placeholders in a block</A>, the calls to the <EM CLASS="Kursiv">
begin</EM>
 and <EM CLASS="Kursiv">
end</EM>
 methods of the <EM CLASS="Kap-">
PhpTempt</EM>
 class are in bold to demonstrate how the structure of the template file perfectly reflects the structure of the constrolling PHP script.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-997987"></A>Within the <EM CLASS="Kursiv">
for</EM>
 loop, the <EM CLASS="Kursiv">
begin</EM>
 method will be called 3 times (for <EM CLASS="Kursiv">
hans</EM>
, <EM CLASS="Kursiv">
dennis</EM>
 and <EM CLASS="Kursiv">
christine</EM>
), indicating to the <EM CLASS="Kap-">
PhpTempt</EM>
 framework that block <EM CLASS="Kursiv">
aBlock</EM>
 will be repeated three times, where in subsequent repetitions the data associated to <EM CLASS="Kursiv">
hans</EM>
, <EM CLASS="Kursiv">
dennis</EM>
 and <EM CLASS="Kursiv">
christine</EM>
, respectively, will be inserted for the respective placeholders.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-997978"></A>To convert the template file from <A HREF="tutorial.html#81964" CLASS="XRef">See Template to produce a list of addresses</A>, say <EM CLASS="Kursiv">
addresses.tpl</EM>
, use the template parser,</P>
<P CLASS="Programm-einzeilig">
<A NAME="pgfId-997932"></A>	tpl addresses.tpl</P>
<P CLASS="Haupttext">
<A NAME="pgfId-997936"></A>assuming the template resides in the current working directory. If you save the script from <A HREF="tutorial.html#49359" CLASS="XRef">See Filling in values into placeholders in a block</A> as <EM CLASS="Kursiv">
addresses.php</EM>
 in the same folder all that remains to be done is requesting the script from within a browser to see the result.</P>
</DIV>
</DIV>
<DIV>
<H3 CLASS="Ueberschrift-2">
<A NAME="pgfId-997266"></A><A NAME="69420"></A>Alternative blocks</H3>
<P CLASS="Haupttext">
<A NAME="pgfId-997267"></A>My colleague Dennis actually convinced me to add alternative blocks to <EM CLASS="Kap-">
PhpTempt</EM>
.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-997965"></A>Again, consider the output in <A HREF="tutorial.html#66465" CLASS="XRef">See Output resulting from a request of the control script</A> of the table template and table control script (<A HREF="tutorial.html#22612" CLASS="XRef">See table template file</A> and <A HREF="tutorial.html#49359" CLASS="XRef">See Filling in values into placeholders in a block</A>, respectively). The control script outputs the placeholder values in two different blocks, one block being an alternative of the other. Thus, in the first iteration, the block named <EM CLASS="Kursiv">
table1</EM>
 will receive some placeholder values. In the second iteration the alternative block, <EM CLASS="Kursiv">
table2</EM>
, will receive placeholder values, while <EM CLASS="Kursiv">
table1</EM>
 will remain empty, in the third iteration, <EM CLASS="Kursiv">
table1</EM>
 will again receive the placeholder values while <EM CLASS="Kursiv">
table2</EM>
 remains empty and so on.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-998631"></A>Once the frameset produces HTML code with a call to the <EM CLASS="Kursiv">
out</EM>
 method of <EM CLASS="Kap-">
PhpTempt</EM>
, the body of the <EM CLASS="Kursiv">
table1</EM>
 block will be repeated multiple times. Whenever the <EM CLASS="Kursiv">
out</EM>
 method (or more precisely, the <EM CLASS="Kursiv">
out</EM>
 method of the object representing block <EM CLASS="Kursiv">
table1</EM>
) encounters a repetition of the <EM CLASS="Kursiv">
table1</EM>
 block for which none of the comprising placeholders has received a value, the method reverts to the alternative block <EM CLASS="Kursiv">
table2</EM>
 and prints its body.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-998759"></A>Note however, that the alternative block is also only printed if at least one of the placeholders contained within, is assigned a value. Thus, if in an iteration neither <EM CLASS="Kursiv">
table1</EM>
 nor <EM CLASS="Kursiv">
table2</EM>
 contained at least one placeholder that has been assigned a value, none of the two blocks would be output in that iteration. For a thorough description of the decision algorithm for <EM CLASS="Kap-">
PhpTempt</EM>
 that determines if a block must be printed or not, <A HREF="tutorial.html#11089" CLASS="XRef">See The rules for repeating blocks</A>.</P>
</DIV>
<DIV>
<H3 CLASS="Ueberschrift-2">
<A NAME="pgfId-997270"></A>Nested blocks</H3>
<P CLASS="Haupttext">
<A NAME="pgfId-997271"></A>Alternative blocks are, in fact, only a shorthand for such situations in which two different outputs must be realized within subsequent iterations of the same repeating block. The general way to achive this would be to use nested blocks.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-998770"></A>Imagine for example, in subsequent iterations of the address table you want to change between 3 different background colours of the table row. The syntax of repeating blocks in template files (<A HREF="tutorial.html#91159" CLASS="XRef">See General syntax of repeating blocks</A>) tells you that it is only possible to specify one alternative for a block. The answer to this problem is, as the title of this paragraph suggests, to use nested blocks.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-998783"></A>The template file below demonstrates how to achive three different colours in subsequent iterations of the same repeating block:</P>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-1002460"></A><A NAME="76261"></A>Template example of nested blocks</H5>
<P CLASS="Programm">
<A NAME="pgfId-1002772"></A>&lt;html&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003182"></A>&lt;head&gt;&lt;title&gt;Nested blocks example&lt;/title&gt;&lt;/head&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003183"></A>&lt;body&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003184"></A>&lt;table&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003185"></A>	&lt;tr&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003186"></A>		&lt;td colspan=&quot;2&quot;&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003187"></A>			&lt;b&gt;Addresses&lt;/b&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003188"></A>		&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003189"></A>	&lt;/tr&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003190"></A>	&lt;tr&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003191"></A>		&lt;td&gt;&lt;b&gt;name&lt;/b&gt;&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003192"></A>		&lt;td&gt;&lt;b&gt;town&lt;/b&gt;&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003193"></A>	&lt;/tr&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003194"></A>	&lt;!--$ begin aBlock--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003195"></A>		&lt;!--$ begin nested1--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003196"></A>			&lt;tr bgcolor=&quot;#909090&quot;&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003197"></A>				&lt;td&gt;&lt;!--$ var NAME--&gt;a name&lt;!--$ end--&gt;&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003198"></A>				&lt;td&gt;&lt;!--$ var TOWN--&gt;a name&lt;!--$ end--&gt;&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003199"></A>			&lt;/tr&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003200"></A>		&lt;!--$ end nested1--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003201"></A>		&lt;!--$ begin nested2--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003202"></A>			&lt;tr bgcolor=&quot;#c0c0c0&quot;&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003203"></A>				&lt;td&gt;&lt;!--$ var NAME--&gt;a name&lt;!--$ end--&gt;&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003204"></A>				&lt;td&gt;&lt;!--$ var TOWN--&gt;a name&lt;!--$ end--&gt;&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003205"></A>			&lt;/tr&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003206"></A>		&lt;!--$ end nested2--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003207"></A>		&lt;!--$ begin nested3--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003208"></A>			&lt;tr bgcolor=&quot;#f0f0f0&quot;&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003209"></A>				&lt;td&gt;&lt;!--$ var NAME--&gt;a name&lt;!--$ end--&gt;&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003210"></A>				&lt;td&gt;&lt;!--$ var TOWN--&gt;a name&lt;!--$ end--&gt;&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003211"></A>			&lt;/tr&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003212"></A>		&lt;!--$ end nested3--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003213"></A>	&lt;!--$ end aBlock--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003214"></A>&lt;/table&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003215"></A>&lt;/body&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003216"></A>&lt;/html&gt;</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1002533"></A>Note, that in order to keep the example small enough to fit one page, the original address book template was cropped down from <A HREF="tutorial.html#62544" CLASS="XRef">See Placeholders in a template file</A>.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-999913"></A>Here is how to add values to the template:</P>
</DIV>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-998915"></A><A NAME="51337"></A>The PHP control script for the 3-colour address table</H5>
<P CLASS="Programm">
<A NAME="pgfId-1002797"></A>&lt;?php</P>
<P CLASS="Programm">
<A NAME="pgfId-1003218"></A>	$data[&quot;name&quot;] = array (&quot;hans&quot;, &quot;dennis&quot;, &quot;christine&quot;, &quot;karl&quot;, &quot;horst&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003219"></A>	$data[&quot;town&quot;] = array (&quot;T&amp;uuml;bingen&quot;, &quot;Reutlingen&quot;, &quot;Paris&quot;, &quot;Toronto&quot;, &quot;G&amp;ouml;hlen&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003220"></A>	include (&quot;phptempt.php&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003221"></A>	$t = new phptempt (&quot;three-color.inc&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003222"></A>	for ($i=0; $i&lt;sizeof($data[&quot;name&quot;]); $i++) {</P>
<P CLASS="Programm">
<A NAME="pgfId-1003223"></A>		$t-&gt;begin (&quot;aBlock&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003224"></A>		if ($i % 3 == 0)</P>
<P CLASS="Programm">
<A NAME="pgfId-1003225"></A>			$t-&gt;begin (&quot;nested1&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003226"></A>		else if ($i % 3 == 1)</P>
<P CLASS="Programm">
<A NAME="pgfId-1003227"></A>			$t-&gt;begin (&quot;nested2&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003228"></A>		else</P>
<P CLASS="Programm">
<A NAME="pgfId-1003229"></A>			$t-&gt;begin (&quot;nested3&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003230"></A>		$t-&gt;addVal (&quot;NAME&quot;, $data[&quot;name&quot;][$i]);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003231"></A>		$t-&gt;addVal (&quot;TOWN&quot;, $data[&quot;town&quot;][$i]);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003232"></A>		if ($i % 3 == 0)</P>
<P CLASS="Programm">
<A NAME="pgfId-1003233"></A>			$t-&gt;end (&quot;nested1&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003234"></A>		else if ($i % 3 == 1)</P>
<P CLASS="Programm">
<A NAME="pgfId-1003235"></A>			$t-&gt;end (&quot;nested2&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003236"></A>		else</P>
<P CLASS="Programm">
<A NAME="pgfId-1003237"></A>			$t-&gt;end (&quot;nested3&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003238"></A>		$t-&gt;end (&quot;aBlock&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003239"></A>	}</P>
<P CLASS="Programm">
<A NAME="pgfId-1003240"></A>	$t-&gt;out ();</P>
<P CLASS="Programm">
<A NAME="pgfId-1003241"></A>?&gt;</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1002598"></A>Again, note how the structure of the template file in <A HREF="tutorial.html#76261" CLASS="XRef">See Template example of nested blocks</A> reflects the structure of the controlling PHP script in <A HREF="tutorial.html#51337" CLASS="XRef">See The PHP control script for the 3-colour address table</A>. The <EM CLASS="Kursiv">
if ... else if</EM>
 construct assures that exactly one of the nested blocks embedded into <EM CLASS="Kursiv">
aBlock</EM>
 at a time receives placeholder values. The placeholders of the other nested blocks will remain undefined and thus, these blocks will not be printed.</P>
</DIV>
</DIV>
<DIV>
<H3 CLASS="Ueberschrift-2">
<A NAME="pgfId-997341"></A><A NAME="16061"></A>The document root block</H3>
<P CLASS="Haupttext">
<A NAME="pgfId-997347"></A>Each template implicitly contains a root block, <EM CLASS="Kursiv">
doc</EM>
, which in turn comprises all placeholders and nested blocks that appear anywhere in the template.You may call up method <EM CLASS="Kursiv">
begin</EM>
 of the <EM CLASS="Kap-">
PhpTempt</EM>
 class on the <EM CLASS="Kursiv">
doc</EM>
 block optionally:</P>
<P CLASS="Programm-einzeilig">
<A NAME="pgfId-997354"></A>	$t-&gt;begin ('doc');</P>
<P CLASS="Haupttext">
<A NAME="pgfId-997368"></A><EM CLASS="Kap-">
PhpTempt</EM>
 calls this method on the <EM CLASS="Kursiv">
doc</EM>
 block when it is first instantiated, and a subsequent call of the method on the <EM CLASS="Kursiv">
doc</EM>
 block is simply ignored.<A HREF="#pgfId-999944" CLASS="footnote">5</A></P>
<P CLASS="Haupttext">
<A NAME="pgfId-999936"></A>A call to method <EM CLASS="Kursiv">
end</EM>
 at the end of your control script closes the document root block:</P>
<P CLASS="Programm-einzeilig">
<A NAME="pgfId-997356"></A>	$t-&gt;end ('doc');</P>
<P CLASS="Haupttext">
<A NAME="pgfId-997385"></A>Again, note that a call to <EM CLASS="Kursiv">
end</EM>
 on the <EM CLASS="Kursiv">
doc</EM>
 block is optional, since in a call to the <EM CLASS="Kursiv">
out</EM>
 method, <EM CLASS="Kap-">
PhpTempt</EM>
 implicitly includes calls to the <EM CLASS="Kursiv">
end</EM>
 method for blocks that have not yet been finished.</P>
</DIV>
<DIV>
<H3 CLASS="Ueberschrift-2">
<A NAME="pgfId-1007139"></A><A NAME="78971"></A>Comments</H3>
<P CLASS="Haupttext">
<A NAME="pgfId-1007230"></A>The text between (and including) the <EM CLASS="Kursiv">
ignore</EM>
-tag and the associated <EM CLASS="Kursiv">
end</EM>
-tag will be skipped when the parser creates the output file. This block type might be useful in cases where both template and generated file need be viewed in a browser but are located in different subdirectories. The comment block can then be used to enclose an HTML <EM CLASS="Kursiv">
base</EM>
 tag, for example:</P>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-1007150"></A>A comment block in a template file</H5>
<P CLASS="Programm">
<A NAME="pgfId-1007237"></A>&lt;html&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1007238"></A>&lt;head&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1007239"></A>	&lt;title&gt;Comment example&lt;/title&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1007240"></A>&lt;/head&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1007241"></A>&lt;body&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1007242"></A>&lt;!--$ ignore --&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1007243"></A>	&lt;base href=&quot;http://hans.hn.org/&quot;&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1007244"></A>&lt;!--$ end--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1007245"></A>&nbsp;</P>
<P CLASS="Programm">
<A NAME="pgfId-1007246"></A>The picture below can be found at &quot;http://hans.hn.org/images/flash.gif&quot; but probably not in the directory where you stored this sample file:&lt;br&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1007248"></A>&nbsp;</P>
<P CLASS="Programm">
<A NAME="pgfId-1007249"></A>&lt;img src=&quot;/images/flash.gif&quot; alt=&quot;flash icon&quot;&gt;.</P>
<P CLASS="Programm">
<A NAME="pgfId-997274"></A>&lt;/body&gt;</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1007276"></A>Compiling this file, <EM CLASS="Kursiv">
comment.tpl</EM>
, with the template parser creates an include file without the <EM CLASS="Kursiv">
base</EM>
 tag.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1007286"></A>A comment block may not contain any <EM CLASS="Kap-">
PhpTempt</EM>
 tags.</P>
</DIV>
</DIV>
<DIV>
<H3 CLASS="Ueberschrift-2">
<A NAME="pgfId-1007310"></A><A NAME="11089"></A>The rules for repeating blocks</H3>
<P CLASS="Haupttext">
<A NAME="pgfId-1007314"></A>The rules to determine if a block should be printed or not are as follows:</P>
<OL>
<LI CLASS="Numeriert-1">
<A NAME="pgfId-1007315"></A>A comment block is never printed.</LI>
<LI CLASS="Numeriert">
<A NAME="pgfId-997260"></A>For repeating blocks determine if the given block contains placeholders or not (whether or not values are assigned to them).</LI>
<LI CLASS="Numeriert">
<A NAME="pgfId-999038"></A>If no placeholders are declared within the block then determine the number of times <EM CLASS="Kursiv">
n</EM>
 that the begin method has been called on this block.</LI>
<LI CLASS="Numeriert-n-n">
<A NAME="pgfId-1002823"></A>Print the contents of the block (HTML code and nested blocks) <EM CLASS="Kursiv">
n</EM>
 times.</LI>
<LI CLASS="Numeriert-n-n">
<A NAME="pgfId-1002819"></A>Nested blocks will decide for themselves if they are printed or not (ie. for each nested block start recursively with step 1, then finish).</LI>
<LI CLASS="Numeriert">
<A NAME="pgfId-999066"></A>Otherwise the block contains placeholders. Determine how many values have been defined for each placeholder. <EM CLASS="Kursiv">
m</EM>
 is the maximum number of values that one placeholder in the block has been assigned to.</LI>
<LI CLASS="Numeriert-n-1">
<A NAME="pgfId-999084"></A>If none of the placeholders has been assigned a value (<EM CLASS="Kursiv">
m</EM>
=0) then do not print the block.</LI>
<LI CLASS="Numeriert-n-n">
<A NAME="pgfId-999088"></A>Otherwise, <EM CLASS="Kursiv">
m</EM>
&gt;0. Print the block <EM CLASS="Kursiv">
m</EM>
 times. If a value is not available for a placeholder, then the framework will occasionally issue a warning, if you entered the debug mode of <EM CLASS="Kap-">
PhpTempt</EM>
, that is likely to corrupt your HTML outputs and leave your script inoperable. </LI>
<LI CLASS="Numeriert-n-n">
<A NAME="pgfId-999030"></A>Nested blocks will decide for themselves if they will be printed or not (ie. for each nested block restart at step 1).</LI>
</OL>
</DIV>
</DIV>
<DIV>
<H2 CLASS="Ueberschrift-1">
<A NAME="pgfId-999030"></A>Conditional blocks</H2>
<P CLASS="Haupttext">
<A NAME="pgfId-1003653"></A>Conditional blocks either check for a specified condition to hold or for a specified placeholder to be set. The contents of conditional blocks are at most printed once.</P>
<DIV>
<H3 CLASS="Ueberschrift-2">
<A NAME="pgfId-1003277"></A>Syntax</H3>
<P CLASS="Haupttext">
<A NAME="pgfId-1003284"></A>The general syntax of conditional blocks in a template file is as follows:</P>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-1006340"></A><A NAME="91159"></A>General syntax of conditional blocks</H5>
<P CLASS="Programm">
<A NAME="pgfId-1006341"></A>	conditional ::= ( conditional_ident | conditional_check );</P>
<P CLASS="Programm">
<A NAME="pgfId-1006298"></A>&nbsp;</P>
<P CLASS="Programm">
<A NAME="pgfId-1006297"></A>	conditional_ident ::=</P>
<P CLASS="Programm">
<A NAME="pgfId-1003649"></A>		&quot;&lt;!--$&quot; &quot;cond&quot; [ &quot;!&quot; ] ident ( ident )* &quot;--&gt;&quot;</P>
<P CLASS="Programm">
<A NAME="pgfId-1006274"></A>			body</P>
<P CLASS="Programm">
<A NAME="pgfId-1006266"></A>		&quot;&lt;!--$&quot; &quot;end&quot; [ &quot;!&quot; ] ident ( ident )* &quot;--&gt;&quot; ;</P>
<P CLASS="Programm">
<A NAME="pgfId-1006277"></A>&nbsp;</P>
<P CLASS="Programm">
<A NAME="pgfId-1006278"></A>	conditional_check ::=</P>
<P CLASS="Programm">
<A NAME="pgfId-1003651"></A>		&quot;&lt;!--$&quot; &quot;check&quot; [ &quot;!&quot; ] placeholder ( placeholder )* &quot;--&gt;&quot;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003291"></A>			body</P>
<P CLASS="Programm">
<A NAME="pgfId-1006291"></A>		&quot;&lt;!--$&quot; &quot;end&quot; [&quot;!&quot;] placeholder ( placeholder )* &quot;--&gt;&quot; ;</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1006239"></A>where <EM CLASS="Kursiv">
placeholder</EM>
 is the name of a placeholder as defined in <A HREF="tutorial.html#10319" CLASS="XRef">See Syntax of placeholder references</A>.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1003705"></A><EM CLASS="Kursiv">
ident</EM>
 specifies one or more conditions under which the body of the conditional block will be printed. A <EM CLASS="Kursiv">
condition</EM>
 in <EM CLASS="Kap-">
PhpTempt</EM>
 template files is a simple identifier: The condition holds as soon as the PHP control script for the template has called up the <EM CLASS="Kursiv">
setCond</EM>
 method of class <EM CLASS="Kursiv">
phptempt</EM>
 on the appropriate condition identifier. If none of the conditions hold the block contents will not be printed.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1003520"></A>The specification of condition identifiers in the <EM CLASS="Kursiv">
end</EM>
 tag of a conditional block is optional. If specified, though, all identifiers listed in the <EM CLASS="Kursiv">
begin</EM>
 tag of the conditional block must be repeated in the <EM CLASS="Kursiv">
end</EM>
 tag. Otherwise, the preprocessor will issue a warning. </P>
<P CLASS="Haupttext">
<A NAME="pgfId-1003733"></A>In contrast, <EM CLASS="Kursiv">
placeholder</EM>
 (<A HREF="tutorial.html#91159" CLASS="XRef">See General syntax of conditional blocks</A>) denotes the name of a placeholder declared in the current block. The block embedded by a pair of <EM CLASS="Kursiv">
check</EM>
 ...<EM CLASS="Kursiv">
end</EM>
 tags will only be printed if the specified placeholder has been set with a call to method <EM CLASS="Kursiv">
addVar</EM>
 in the current block iteration.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1004299"></A>Note finally, that the list of identifiers can be preceded by an exclamation mark (&quot;!&quot;) in the sense of a negation. The contents of a conditional block like the one in the figure below,</P>
</DIV>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-1004302"></A>Negation of a condition</H5>
<P CLASS="Programm">
<A NAME="pgfId-1004308"></A>&lt;!--$ check ! c1 c2 --&gt; </P>
<P CLASS="Programm">
<A NAME="pgfId-1004312"></A>	...</P>
<P CLASS="Programm">
<A NAME="pgfId-1004313"></A>&lt;!--$ end--&gt;</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1004314"></A>will only be printed if none of the conditions <EM CLASS="Kursiv">
c1</EM>
 and <EM CLASS="Kursiv">
c2</EM>
 have been set by the controlling PHP script.</P>
</DIV>
</DIV>
<DIV>
<H3 CLASS="Ueberschrift-2">
<A NAME="pgfId-1003504"></A>A simple example using the cond tag</H3>
<P CLASS="Haupttext">
<A NAME="pgfId-1003314"></A>As an example of the use of <EM CLASS="Kursiv">
cond</EM>
 tags, consider the following template that offers different interfaces to the user according to the current condition:</P>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-1003315"></A><A NAME="99823"></A>Conditional block in a template file using the cond tag</H5>
<P CLASS="Programm">
<A NAME="pgfId-1003586"></A>&lt;html&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003587"></A>&lt;head&gt;&lt;title&gt;Conditional block example&lt;/title&gt;&lt;/head&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003588"></A>&lt;body&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003589"></A>&lt;!--$ cond admin--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003590"></A>	&lt;a href=&quot;change.php&quot;&gt;change entry&lt;/a&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003591"></A>&lt;!--$ end admin--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003592"></A>&lt;!--$ cond admin user--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003593"></A>	&lt;a href=&quot;view.php&quot;&gt;view entry&lt;/a&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003594"></A>&lt;!--$ end admin user--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003595"></A>&lt;!--$ cond error--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003596"></A>    The following error occurred: '{ERR}'.</P>
<P CLASS="Programm">
<A NAME="pgfId-1003597"></A>&lt;!--$ end error--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003598"></A>&lt;/body&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003401"></A>&lt;/html&gt;</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1003611"></A>The PHP script to control the template above (stored as, say, <EM CLASS="Kursiv">
cond.tpl</EM>
) would look somewhat like:</P>
</DIV>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-1003405"></A>PHP script to control conditional blocks</H5>
<P CLASS="Programm">
<A NAME="pgfId-1003616"></A>&lt;?php</P>
<P CLASS="Programm">
<A NAME="pgfId-1003617"></A>    include (&quot;phptempt.php&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003618"></A>    $t = new PhpTempt (&quot;cond.inc&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003619"></A>    if (isset($id)) {</P>
<P CLASS="Programm">
<A NAME="pgfId-1003620"></A>    	if ($id==1) /* admin condition? */</P>
<P CLASS="Programm">
<A NAME="pgfId-1003621"></A>    		$t-&gt;setCond (&quot;admin&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003622"></A>    	else if ($id==2) /* user condition? */</P>
<P CLASS="Programm">
<A NAME="pgfId-1003623"></A>    		$t-&gt;setCond (&quot;user&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003624"></A>    	else { /* error condition! */</P>
<P CLASS="Programm">
<A NAME="pgfId-1003625"></A>    		$t-&gt;addVal (&quot;ERR&quot;, &quot;Illegal value for &#92;$id: $id&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003626"></A>    		$t-&gt;setCond (&quot;error&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003627"></A>    	}</P>
<P CLASS="Programm">
<A NAME="pgfId-1003628"></A>    }</P>
<P CLASS="Programm">
<A NAME="pgfId-1003629"></A>    else { /* no $id provided, error condition! */</P>
<P CLASS="Programm">
<A NAME="pgfId-1003630"></A>    	$t-&gt;addVal (&quot;ERR&quot;, &quot;Please supply value for parameter &#92;$id.&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003631"></A>    	$t-&gt;setCond (&quot;error&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003632"></A>    }</P>
<P CLASS="Programm">
<A NAME="pgfId-1003633"></A>    $t-&gt;out ();</P>
<P CLASS="Programm">
<A NAME="pgfId-1003449"></A>?&gt;</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1003450"></A>Using method <EM CLASS="Kursiv">
setCond</EM>
 of class <EM CLASS="Kap-">
PhpTempt</EM>
, one of the conditions <EM CLASS="Kursiv">
admin</EM>
 or <EM CLASS="Kursiv">
user</EM>
 is set. If <EM CLASS="Kursiv">
$id</EM>
 equals 1 the condition <EM CLASS="Kursiv">
admin</EM>
 will hold and a call to the <EM CLASS="Kursiv">
out</EM>
 method will result in an HTML file with two links, &quot;change entry&quot; and &quot;view entry&quot;. In contrast, if <EM CLASS="Kursiv">
$id</EM>
 equals 2 only the second link, &quot;view entry&quot; will be printed.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1003461"></A>Note that only one condition can hold for a template at a time. Subsequent calls will overwrite the condition set in a previous call to <EM CLASS="Kursiv">
setCond</EM>
. If <EM CLASS="Kursiv">
$id</EM>
 has not been supplied or has a value different from 1 or 2 then the <EM CLASS="Kursiv">
error</EM>
 condition holds for the template in <A HREF="tutorial.html#99823" CLASS="XRef">See Conditional block in a template file using the cond tag</A> and none of the links will be printed. Instead, the script will add a value for the <EM CLASS="Kursiv">
ERR</EM>
 placeholder which will be printed in the <EM CLASS="Kursiv">
out</EM>
 method.</P>
</DIV>
</DIV>
<DIV>
<H3 CLASS="Ueberschrift-2">
<A NAME="pgfId-1003742"></A>A simple example using the check tag</H3>
<P CLASS="Haupttext">
<A NAME="pgfId-1003743"></A>In some situations where a condition changes from one iteration to another, the check tag can be used instead of the cond tag. The figure below gives you an example:</P>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-1003771"></A>Example of using the check tag</H5>
<P CLASS="Programm">
<A NAME="pgfId-1003807"></A>&lt;html&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003821"></A>&lt;head&gt;&lt;title&gt;Check block test&lt;/title&gt;&lt;/head&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003822"></A>&lt;body&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003823"></A>&lt;table border=&quot;1&quot; width=&quot;60%&quot;&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003824"></A>	&lt;tr&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003857"></A>		&lt;td width=&quot;30%&quot;&gt;&lt;b&gt;Name&lt;/b&gt;&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003828"></A>		&lt;td width=&quot;70%&quot;&gt;&lt;b&gt;Projects&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003832"></A>	&lt;!--$ begin nameblock--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003833"></A>		&lt;tr&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003834"></A>			&lt;td valign=&quot;top&quot;&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003835"></A>				&lt;!--$ var NAME--&gt;Hans&lt;!--$ end NAME--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003836"></A>			&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003837"></A>			&lt;td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003838"></A>				&lt;!--$ begin projectblock--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003839"></A>					&lt;!--$ var PROJECT--&gt;Name of a project&lt;!--$end--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003840"></A>					&lt;!--$ check READY CANCELLED--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003864"></A>						(</P>
<P CLASS="Programm">
<A NAME="pgfId-1003868"></A>					&lt;!--$ end READY CANCELLED--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003865"></A>					&lt;!--$ check CANCELLED--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003866"></A>						&lt;em&gt;cancelled&lt;/em&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003867"></A>						&lt;!--$ check READY--&gt;,&lt;!--$ end READY--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003841"></A>					&lt;!--$ end CANCELLED--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003842"></A>					&lt;!--$ check READY--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003869"></A>						&lt;em&gt;finished&lt;/em&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003870"></A>					&lt;!--$ end READY--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003871"></A>					&lt;!--$ check READY CANCELLED--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003872"></A>						)</P>
<P CLASS="Programm">
<A NAME="pgfId-1003843"></A>					&lt;!--$ end CANCELLED READY --&gt;&lt;br&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003844"></A>				&lt;!--$ end projectblock--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003845"></A>			&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003846"></A>		&lt;/tr&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003847"></A>	&lt;!--$ end nameblock--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003848"></A>&lt;/table&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003849"></A>&lt;/body&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003850"></A>&lt;/html&gt;</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1003873"></A>The PHP script to control the template above is depicted below:</P>
</DIV>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-1003947"></A>PHP control script for the check tag example</H5>
<P CLASS="Programm">
<A NAME="pgfId-1003938"></A>&lt;?php</P>
<P CLASS="Programm">
<A NAME="pgfId-1003958"></A>	include (&quot;phptempt.php&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003959"></A>	$t = new phptempt (&quot;check-block.inc&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003961"></A>	// data:</P>
<P CLASS="Programm">
<A NAME="pgfId-1003962"></A>	$names = array (&quot;Hans&quot;, &quot;Dennis&quot;, &quot;Matthias&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003964"></A>	$projects = array (</P>
<P CLASS="Programm">
<A NAME="pgfId-1003965"></A>		&quot;Hans&quot; =&gt; array (&quot;phptempt&quot;, &quot;diff&quot;, &quot;game&quot;),</P>
<P CLASS="Programm">
<A NAME="pgfId-1003966"></A>		&quot;Dennis&quot; =&gt; array (&quot;bookmarks&quot;),</P>
<P CLASS="Programm">
<A NAME="pgfId-1003967"></A>		&quot;Matthias&quot; =&gt; array (&quot;money&quot;, &quot;dynamight&quot;)</P>
<P CLASS="Programm">
<A NAME="pgfId-1003968"></A>	);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003970"></A>	$cancelled = array (&quot;game&quot; =&gt; true, &quot;dynamight&quot; =&gt; true);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003971"></A>	$ready = array (</P>
<P CLASS="Programm">
<A NAME="pgfId-1003972"></A>		&quot;bookmarks&quot; =&gt; true, &quot;money&quot; =&gt; true, &quot;phptempt&quot; =&gt; true</P>
<P CLASS="Programm">
<A NAME="pgfId-1003973"></A>	);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003976"></A>	// fill data into template:</P>
<P CLASS="Programm">
<A NAME="pgfId-1003978"></A>	for ($i=0; $i&lt;sizeof($names); $i++) {</P>
<P CLASS="Programm">
<A NAME="pgfId-1003980"></A>		$name = $names[$i];</P>
<P CLASS="Programm">
<A NAME="pgfId-1003981"></A>		$t-&gt;begin (&quot;nameblock&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003983"></A>		$t-&gt;addVal (&quot;NAME&quot;, $name);</P>
<P CLASS="Programm">
<A NAME="pgfId-1004026"></A>&nbsp;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003985"></A>		for ($j=0; $j&lt;sizeof($projects[$name]); $j++) {</P>
<P CLASS="Programm">
<A NAME="pgfId-1003987"></A>			$project = $projects[$name][$j];</P>
<P CLASS="Programm">
<A NAME="pgfId-1003988"></A>			$t-&gt;begin (&quot;projectblock&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003990"></A>			$t-&gt;addVal (&quot;PROJECT&quot;, $project);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003993"></A>			if (isset($cancelled[$project])) {</P>
<P CLASS="Programm">
<A NAME="pgfId-1003994"></A>				$t-&gt;addVal (&quot;CANCELLED&quot;, &quot;set&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003995"></A>			}</P>
<P CLASS="Programm">
<A NAME="pgfId-1003996"></A>			if (isset($ready[$project]))</P>
<P CLASS="Programm">
<A NAME="pgfId-1003997"></A>				$t-&gt;addVal (&quot;READY&quot;, &quot;set&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1003998"></A>&nbsp;</P>
<P CLASS="Programm">
<A NAME="pgfId-1003999"></A>			$t-&gt;end (&quot;projectblock&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1004000"></A>		}</P>
<P CLASS="Programm">
<A NAME="pgfId-1004002"></A>		$t-&gt;end (&quot;nameblock&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1004003"></A>	}</P>
<P CLASS="Programm">
<A NAME="pgfId-1004005"></A>	$t-&gt;out();</P>
<P CLASS="Programm">
<A NAME="pgfId-1004007"></A>?&gt;</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1004046"></A>For each name in the <EM CLASS="Kursiv">
names</EM>
 array the script checks for the projects associated with that name in the <EM CLASS="Kursiv">
projects</EM>
 array. It prints the current name in the first table column, then in the second column prints each project associated with that person and adds the marker text <EM CLASS="Kursiv">
cancelled</EM>
 and/or <EM CLASS="Kursiv">
finished</EM>
 for those projects that are set to <EM CLASS="Kursiv">
true</EM>
 in the <EM CLASS="Kursiv">
cancelled</EM>
 and <EM CLASS="Kursiv">
ready</EM>
 arrays, respectively. Note that a particular project may be contained in both arrays.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1004098"></A>For example, in the nested loop for &quot;Hans&quot; the script will find that project &quot;game&quot; is contained in both the <EM CLASS="Kursiv">
cancelled</EM>
 and the <EM CLASS="Kursiv">
ready</EM>
 arrays and will thus add values for the placeholders <EM CLASS="Kursiv">
CANCELLED</EM>
 and <EM CLASS="Kursiv">
READY</EM>
 to the iteration of the projectblock and its embedding nameblock.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1004109"></A>Later, when printing the contents of the template by calling up the <EM CLASS="Kursiv">
out</EM>
 method, <EM CLASS="Kap-">
PhpTempt</EM>
 will actually print a parenthesis &quot;(&quot; after the &quot;game&quot; project, since at least one of the <EM CLASS="Kursiv">
CANCELLED</EM>
 and <EM CLASS="Kursiv">
READY</EM>
 variables has been set before<A HREF="#pgfId-1004107" CLASS="footnote">6</A>, followed by the cancelled marker text, then, as the READY placeholder has also been defined for this iteration, a comma and the ready marker text and, finally, a closing parenthesis &quot;)&quot;.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1004259"></A>The <A HREF="tutorial.html#90019" CLASS="XRef">See The output resulting from a request of the check tag example script</A> below shows the output of the script in a browser window.</P>
<OL>
<LI CLASS="Bildunterschrift">
<A NAME="pgfId-1004161"></A><A NAME="90019"></A>The output resulting from a request of the check tag example script</LI>
<IMG SRC="tutorial-4.gif" ALIGN="RIGHT">
</OL>
</DIV>
</DIV>
</DIV>
<DIV>
<H2 CLASS="Ueberschrift-1">
<A NAME="pgfId-999209"></A><A NAME="36844"></A>References to placeholders</H2>
<DIV>
<H3 CLASS="Ueberschrift-2">
<A NAME="pgfId-1000282"></A>Syntax</H3>
<P CLASS="Haupttext">
<A NAME="pgfId-1001455"></A>In <EM CLASS="Kap-">
PhpTempt</EM>
, references to placeholders can take the following forms:</P>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-999215"></A><A NAME="10319"></A>Syntax of placeholder references</H5>
<P CLASS="Programm">
<A NAME="pgfId-999216"></A>	placeholder ::=</P>
<P CLASS="Programm">
<A NAME="pgfId-999217"></A>			&quot;^&quot; blockident ( &quot;.&quot; blockident )* &quot;#&quot; ident</P>
<P CLASS="Programm">
<A NAME="pgfId-1001118"></A>		|	&quot;^&quot; ( &quot;.&quot; blockident )* &quot;#&quot; ident</P>
<P CLASS="Programm">
<A NAME="pgfId-1001131"></A>		|	blockident ( &quot;.&quot; blockident )* &quot;#&quot; ident</P>
<P CLASS="Programm">
<A NAME="pgfId-999218"></A>		|	ident</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1001488"></A><EM CLASS="Kursiv">
blockident</EM>
 entities of the placeholder name are called <EM CLASS="Kursiv">
block</EM>
 <EM CLASS="Kursiv">
identifiers</EM>
. A sequence of such block identifiers, separated by dots (.) make up a (block) <EM CLASS="Kursiv">
path</EM>
.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1001492"></A>Internally, <EM CLASS="Kap-">
PhpTempt</EM>
 stores placeholder names in their fully qualified form. A <EM CLASS="Kursiv">
fully qualified placeholder</EM>
 starts with the document root block <EM CLASS="Kursiv">
doc</EM>
 (<A HREF="tutorial.html#16061" CLASS="XRef">See The document root block</A>) and has no leading ^-Symbol. The path of these fully qualified placeholders is called an <EM CLASS="Kursiv">
absolute</EM>
 path. Examples for such placeholder names are:</P>
</DIV>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-999224"></A>Examples of fully qualified placeholder names</H5>
<P CLASS="Programm">
<A NAME="pgfId-999225"></A>doc#NAME<BR>
doc#TOWN<BR>
doc.table1#NAME<BR>
doc.table2#NAME</P>
<P CLASS="Haupttext">
<A NAME="pgfId-999226"></A>Two placeholders declared in different blocks with the same name, for example <EM CLASS="Kursiv">
NAME</EM>
 in blocks <EM CLASS="Kursiv">
table1</EM>
 and <EM CLASS="Kursiv">
table2</EM>
 (<A HREF="tutorial.html#22612" CLASS="XRef">See table template file</A>), actually denote different values.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-999230"></A>A qualified placeholder with <EM CLASS="Kursiv">
relative </EM>
path is preceded by the ^-Symbol. It denotes a placeholder in another block relative to the block in which the reference occurs. Examples for placeholder names with relative path are:</P>
</DIV>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-999231"></A>Examples of  placeholder names with relative path</H5>
<P CLASS="Programm">
<A NAME="pgfId-1001083"></A>^table1#name</P>
<P CLASS="Programm">
<A NAME="pgfId-1001099"></A>^.table1#name</P>
<P CLASS="Programm">
<A NAME="pgfId-999233"></A>^table2#name</P>
<P CLASS="Programm">
<A NAME="pgfId-1001109"></A>^#name</P>
<P CLASS="Haupttext">
<A NAME="pgfId-999234"></A>You may reference a placeholder in another repeating block in one of the following situations:</P>
<UL>
<LI CLASS="Markiert">
<A NAME="pgfId-999235"></A>The placeholder is declared in the same block as the reference, or:</LI>
<LI CLASS="Markiert">
<A NAME="pgfId-999236"></A>The placeholder is declared in one of the parent blocks of the block that contain the reference, or:</LI>
<LI CLASS="Markiert">
<A NAME="pgfId-1001204"></A>The placeholder is declared in a block with the same nesting level as the block which contains the reference. For example, the placeholders in the listing below have all the same nesting level of 2:</LI>
</UL>
</DIV>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-1001235"></A><A NAME="63367"></A>A list of placeholders with block nesting level of 2</H5>
<OL>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1001220"></A>doc.blockA#ident</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1001221"></A>^blockA#ident<BR>
		(if it occurs, for example, in block doc.blockA.blockB)</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1001255"></A>doc.blockB#ph</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1001258"></A>^.blockB#ph<BR>
		(if it occurs, for example, in block doc.blockA)</LI>
</OL>
<P CLASS="Haupttext">
<A NAME="pgfId-1001263"></A>Note that in <A HREF="tutorial.html#63367" CLASS="XRef">See A list of placeholders with block nesting level of 2</A>, the first and second as well as the third and forth placeholder, respectively, denote in fact identical placeholders.</P>
</DIV>
</DIV>
<DIV>
<H3 CLASS="Ueberschrift-2">
<A NAME="pgfId-1000305"></A>Usage of fully qualified placeholders</H3>
<P CLASS="Haupttext">
<A NAME="pgfId-999237"></A>Below is an example of the use of fully qualified placeholder names in a template file:</P>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-999238"></A>Using fully qualified names in a template</H5>
<P CLASS="Programm">
<A NAME="pgfId-999239"></A>&lt;tr bgcolor=&quot;#9090f0&quot;&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-999240"></A>    &lt;td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-999241"></A>        &lt;!--$ begin referer--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-999242"></A>            Called from {REF} (ID is {REFID}</P>
<P CLASS="Programm">
<A NAME="pgfId-999243"></A>        &lt;!--$ end referer--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-999244"></A>    &lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-999245"></A>&lt;/tr&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-999246"></A>&lt;tr bgcolor=&quot;#c0c0f0&quot;&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-999247"></A>    &lt;td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-999248"></A>        Persons associated with '{NAME}' (ID is {ID}).</P>
<P CLASS="Programm">
<A NAME="pgfId-999249"></A>    &lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-999250"></A>&lt;/tr&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-999251"></A>&lt;tr bgcolor=&quot;#e0e0f0&quot;&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-999252"></A>    &lt;td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-999253"></A>        &lt;ul&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-999254"></A>        &lt;!--$ begin entries--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-999255"></A>            &lt;li&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-999256"></A>                &lt;a href=&quot;#?rid={doc#ID}&amp;id={PERSONID}&quot;</P>
<P CLASS="Programm">
<A NAME="pgfId-999257"></A>				&gt;{PERSON}&lt;/a&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-999258"></A>            &lt;/li&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-999259"></A>        &lt;!--$ end entries--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-999260"></A>        &lt;/ul&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-999261"></A>    &lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-999262"></A>&lt;/tr&gt;</P>
<P CLASS="Bild-in-Absatz">
<A NAME="pgfId-999263"></A>In the <EM CLASS="Kursiv">
entries</EM>
 block <EM CLASS="Kursiv">
doc#ID</EM>
 is a reference to a placeholder. The reference will be replaced by the value of the placeholder ID declared in the <EM CLASS="Kursiv">
doc</EM>
 block when the <EM CLASS="Kursiv">
out</EM>
 method of class <EM CLASS="Kap-">
PhpTempt</EM>
 is called. A PHP script that controls the template might look like as follows:</P>
</DIV>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-999267"></A>PHP control script for the placeholder reference example</H5>
<P CLASS="Programm">
<A NAME="pgfId-999268"></A>&lt;?php</P>
<P CLASS="Programm">
<A NAME="pgfId-999269"></A>	include (&quot;phptempt.php&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-999270"></A>	$t = new phptempt (&quot;fully-qualified.inc&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-999271"></A>	// array of names:</P>
<P CLASS="Programm">
<A NAME="pgfId-999272"></A>	$names = array (&quot;hans&quot;, &quot;dennis&quot;, &quot;christine&quot;, &quot;karin&quot;, &quot;heike&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-999273"></A>	// associations:</P>
<P CLASS="Programm">
<A NAME="pgfId-999274"></A>	$assocs = array (</P>
<P CLASS="Programm">
<A NAME="pgfId-999275"></A>		array (1, 3, 4),</P>
<P CLASS="Programm">
<A NAME="pgfId-999276"></A>		array (2, 3, 4),</P>
<P CLASS="Programm">
<A NAME="pgfId-999277"></A>		array (1),</P>
<P CLASS="Programm">
<A NAME="pgfId-999278"></A>		array (3, 4),</P>
<P CLASS="Programm">
<A NAME="pgfId-999279"></A>		array (1, 2, 3)</P>
<P CLASS="Programm">
<A NAME="pgfId-999280"></A>	);</P>
<P CLASS="Programm">
<A NAME="pgfId-999281"></A>	if (isset($rid)) { // set content of &quot;referer&quot; block</P>
<P CLASS="Programm">
<A NAME="pgfId-999282"></A>		$t-&gt;begin (&quot;referer&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-999283"></A>		$t-&gt;addVal (&quot;REF&quot;, $names[$rid]);</P>
<P CLASS="Programm">
<A NAME="pgfId-999284"></A>		$t-&gt;addVal (&quot;REFID&quot;, $rid);</P>
<P CLASS="Programm">
<A NAME="pgfId-999285"></A>		$t-&gt;end (&quot;referer&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-999286"></A>	}</P>
<P CLASS="Programm">
<A NAME="pgfId-999287"></A>	if (!isset($id)) // default for $id variable</P>
<P CLASS="Programm">
<A NAME="pgfId-999288"></A>		$id = 0;</P>
<P CLASS="Programm">
<A NAME="pgfId-999289"></A>	$t-&gt;addVal (&quot;ID&quot;, $id);</P>
<P CLASS="Programm">
<A NAME="pgfId-999290"></A>	$t-&gt;addVal (&quot;NAME&quot;, $names[$id]);</P>
<P CLASS="Programm">
<A NAME="pgfId-999291"></A>	// add names associated with the above to the template:</P>
<P CLASS="Programm">
<A NAME="pgfId-999292"></A>	for ($i=0; $i&lt;sizeof($assocs[$id]); $i++) {</P>
<P CLASS="Programm">
<A NAME="pgfId-999293"></A>		$t-&gt;begin (&quot;entries&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-999294"></A>		$t-&gt;addVal (&quot;PERSON&quot;, $names[$assocs[$id][$i]]);</P>
<P CLASS="Programm">
<A NAME="pgfId-999295"></A>		$t-&gt;addVal (&quot;PERSONID&quot;, $assocs[$id][$i]);</P>
<P CLASS="Programm">
<A NAME="pgfId-999296"></A>		$t-&gt;end (&quot;entries&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-999297"></A>	}</P>
<P CLASS="Programm">
<A NAME="pgfId-999298"></A>	$t-&gt;out();</P>
<P CLASS="Programm">
<A NAME="pgfId-999299"></A>?&gt;</P>
</DIV>
</DIV>
<DIV>
<H3 CLASS="Ueberschrift-2">
<A NAME="pgfId-999206"></A><A NAME="74774"></A>References to the parent block</H3>
<P CLASS="Haupttext">
<A NAME="pgfId-1000324"></A>In order to be able to &quot;copy-and-paste&quot; portions of one template file into another, you may want to try placeholders with relative instead of absolute paths.<A HREF="#pgfId-1000429" CLASS="footnote">7</A></P>
<P CLASS="Haupttext">
<A NAME="pgfId-1000462"></A>Consider the following template that is designed for use in a Java program. It contains some placeholder names with absolute paths:</P>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-1000468"></A><A NAME="99052"></A>Template containing placeholder references with absolute paths</H5>
<P CLASS="Programm">
<A NAME="pgfId-1000497"></A>// Database entries</P>
<P CLASS="Programm">
<A NAME="pgfId-1000498"></A>&nbsp;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000499"></A>Key/Name								&lt;!--$ begin list1--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000500"></A>{KEY} {NAME}								&lt;!--$ end list1--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000501"></A>&nbsp;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000502"></A>Key/Email								&lt;!--$ begin list2--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000503"></A>{doc.list1#KEY} {EMAIL}								&lt;!--$ end list2--&gt;</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1000487"></A>To be able to include the above template in a Java program as, say <EM CLASS="Kursiv">
namelist_inc.java</EM>
, first store the template under <EM CLASS="Kursiv">
namelist.txt</EM>
 then use the template parser,</P>
<P CLASS="Programm-einzeilig">
<A NAME="pgfId-1000540"></A>	tpl namelist.txt -j</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1000551"></A>to generate a Java include file <EM CLASS="Kursiv">
namelist_inc.java</EM>
 that contains the template. Next, compile this include file,</P>
<P CLASS="Programm-einzeilig">
<A NAME="pgfId-1000554"></A>	javac -classpath .:/usr/local/phptempt/java-src &#92;<BR>
		namelist_inc.java</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1000563"></A>The following Java source code will create a file <EM CLASS="Kursiv">
namelist.out</EM>
:</P>
</DIV>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-1000566"></A><A NAME="33515"></A>Java source code to create output from the template</H5>
<P CLASS="Programm">
<A NAME="pgfId-1000574"></A>import phptempt.*;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000576"></A>public class namelist {</P>
<P CLASS="Programm">
<A NAME="pgfId-1000578"></A>	static String[] name = { &quot;Hans&quot;, &quot;Peter&quot;, &quot;Christine&quot; };</P>
<P CLASS="Programm">
<A NAME="pgfId-1000584"></A>	static String[] email = { &quot;hide@address.com&quot;, null, null };</P>
<P CLASS="Programm">
<A NAME="pgfId-1000590"></A>	public static void main (String[] args) {</P>
<P CLASS="Programm">
<A NAME="pgfId-1000592"></A>		Phptempt t = new Phptempt (&quot;namelist_inc&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1000594"></A>		for (int i=0; i&lt;name.length; i++) {</P>
<P CLASS="Programm">
<A NAME="pgfId-1000596"></A>			t.begin (&quot;list1&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1000597"></A>			t.addVal (&quot;KEY&quot;, Integer.toString(i));</P>
<P CLASS="Programm">
<A NAME="pgfId-1000598"></A>			t.addVal (&quot;NAME&quot;, name[i]);</P>
<P CLASS="Programm">
<A NAME="pgfId-1000599"></A>			t.end (&quot;list1&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1000601"></A>			t.begin (&quot;list2&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1000602"></A>			if (email[i]==null)</P>
<P CLASS="Programm">
<A NAME="pgfId-1000603"></A>				t.addVal (&quot;EMAIL&quot;, &quot;no email&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1000604"></A>			else</P>
<P CLASS="Programm">
<A NAME="pgfId-1000605"></A>				t.addVal (&quot;EMAIL&quot;, email[i]);</P>
<P CLASS="Programm">
<A NAME="pgfId-1000606"></A>			t.end (&quot;list2&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1000608"></A>		}</P>
<P CLASS="Programm">
<A NAME="pgfId-1000610"></A>		t.write (&quot;namelist.out&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1000611"></A>	}</P>
<P CLASS="Programm">
<A NAME="pgfId-1000572"></A>}</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1000726"></A>To compile this Java program in, say, <EM CLASS="Kursiv">
namelist.java</EM>
, type</P>
<P CLASS="Programm-einzeilig">
<A NAME="pgfId-1000730"></A>	javac -classpath /usr/local/phptempt namelist.java</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1000731"></A>Here is the output of the program:</P>
</DIV>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-1000735"></A>Output of the Java program of <A HREF="tutorial.html#33515" CLASS="XRef">See Java source code to create output from the template</A></H5>
<P CLASS="Programm">
<A NAME="pgfId-1000749"></A>// Database entries</P>
<P CLASS="Programm">
<A NAME="pgfId-1000750"></A>&nbsp;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000751"></A>Key/Name</P>
<P CLASS="Programm">
<A NAME="pgfId-1000752"></A>0 Hans</P>
<P CLASS="Programm">
<A NAME="pgfId-1000753"></A>1 Peter</P>
<P CLASS="Programm">
<A NAME="pgfId-1000754"></A>2 Christine</P>
<P CLASS="Programm">
<A NAME="pgfId-1000755"></A>&nbsp;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000756"></A>Key/Email</P>
<P CLASS="Programm">
<A NAME="pgfId-1000757"></A>0 hide@address.com</P>
<P CLASS="Programm">
<A NAME="pgfId-1000758"></A>1 no email</P>
<P CLASS="Programm">
<A NAME="pgfId-1000759"></A>2 no email</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1000747"></A>It is interesting to note how the placeholder <EM CLASS="Kursiv">
KEY</EM>
 from block <EM CLASS="Kursiv">
doc.list1</EM>
 is referenced in block <EM CLASS="Kursiv">
list2</EM>
. To understand the referencing system, we count the number of each call to the <EM CLASS="Kursiv">
begin</EM>
 method of the template <EM CLASS="Kursiv">
t</EM>
 in the Java program which leads us to the situation depicted in the following list:</P>
</DIV>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-1000793"></A>Number of calls of the begin method for each block</H5>
<P CLASS="Programm">
<A NAME="pgfId-1000799"></A>doc			[1]</P>
<P CLASS="Programm">
<A NAME="pgfId-1000815"></A>	list1		[1]</P>
<P CLASS="Programm">
<A NAME="pgfId-1000816"></A>		0 Hans</P>
<P CLASS="Programm">
<A NAME="pgfId-1000817"></A>	list2		[1]</P>
<P CLASS="Programm">
<A NAME="pgfId-1000818"></A>		0 hide@address.com</P>
<P CLASS="Programm">
<A NAME="pgfId-1000837"></A>	list1		[2]</P>
<P CLASS="Programm">
<A NAME="pgfId-1000838"></A>		1 Peter</P>
<P CLASS="Programm">
<A NAME="pgfId-1000839"></A>	list2		[2]</P>
<P CLASS="Programm">
<A NAME="pgfId-1000840"></A>		0 no email</P>
<P CLASS="Programm">
<A NAME="pgfId-1000844"></A>	list1		[3]</P>
<P CLASS="Programm">
<A NAME="pgfId-1000845"></A>		1 Christine</P>
<P CLASS="Programm">
<A NAME="pgfId-1000846"></A>	list2		[3]</P>
<P CLASS="Programm">
<A NAME="pgfId-1000847"></A>		0 no email</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1000809"></A>Since the <EM CLASS="Kursiv">
list1</EM>
 block precedes <EM CLASS="Kursiv">
list2</EM>
 in the template file, <EM CLASS="Kap-">
PhpTempt</EM>
 will print the contents of the <EM CLASS="Kursiv">
list1</EM>
 block before the contents of block <EM CLASS="Kursiv">
list2</EM>
. On doing so, the order in which the data were injected into the blocks determines the order of the data output.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1000893"></A>A reference of a placeholder of block <EM CLASS="Kursiv">
list2</EM>
 from within repetition <EM CLASS="Kursiv">
i</EM>
 of block <EM CLASS="Kursiv">
list2</EM>
 means: print the value of that placeholder in repetition <EM CLASS="Kursiv">
i</EM>
 of block <EM CLASS="Kursiv">
list1</EM>
.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1000913"></A>So far so good. Now imagine that we want to reuse a portion of the above template in other templates. There is no way to include templates in <EM CLASS="Kap-">
PhpTempt</EM>
, so we use &quot;copy-and-paste&quot; ... and realize that we have to change every occurrence of a placeholder reference in situations where the copied portion is embedded in an additional block. This is where relative references come into play.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1000975"></A>Consider the template depicted below. It contains the template of <A HREF="tutorial.html#99052" CLASS="XRef">See Template containing placeholder references with absolute paths</A> where the placeholder reference has slightly changed. It now refers to its target relative to the block in which it is itself contained.</P>
</DIV>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-1000933"></A><A NAME="32895"></A>&nbsp;</H5>
<P CLASS="Programm">
<A NAME="pgfId-1001031"></A>// Database entries</P>
<P CLASS="Programm">
<A NAME="pgfId-1001044"></A>&lt;!--$begin additional--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001033"></A>Key/Name								&lt;!--$ begin list1--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001034"></A>{KEY} {NAME}								&lt;!--$ end list1--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001035"></A>&nbsp;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001036"></A>Key/Email								&lt;!--$ begin list2--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1001037"></A>{^.list1#KEY} {EMAIL}								&lt;!--$ end list2--&gt;&lt;!--$end additional--&gt;</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1001026"></A>The placeholder reference <EM CLASS="Kursiv">
^.list1#KEY</EM>
 is a reference to the block <EM CLASS="Kursiv">
list1</EM>
 in the parent block of <EM CLASS="Kursiv">
list2</EM>
, in other words (and expressed by means of an absolute path) a reference to the placeholder <EM CLASS="Kursiv">
doc.additional.list1#KEY</EM>
. Referring back to <A HREF="tutorial.html#99052" CLASS="XRef">See Template containing placeholder references with absolute paths</A>, we simply have to replace the <EM CLASS="Kursiv">
doc</EM>
 block with the ^-Symbol (pronounce: &quot;parent block&quot;) to yield the same result as before. But this time we can copy-and-paste the whole construction without the need to change each placeholder reference from <EM CLASS="Kursiv">
doc.list1#KEY</EM>
 to <EM CLASS="Kursiv">
doc.additional.list1.KEY</EM>
.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1001417"></A>Later, in <A HREF="tutorial.html#65722" CLASS="XRef">See Relative paths in recursive templates</A>, we will get to now a more general aproach to reference placeholders relative to the current block.</P>
</DIV>
</DIV>
<DIV>
<H3 CLASS="Ueberschrift-2">
<A NAME="pgfId-1000334"></A>Another example for the use of the <EM CLASS="Kursiv">
check</EM>
 tag</H3>
<P CLASS="Haupttext">
<A NAME="pgfId-1000335"></A>Since it is possible to specify a fully qualified placeholder name in a <EM CLASS="Kursiv">
check</EM>
 block, you can simulate the behaviour of a <EM CLASS="Kursiv">
cond</EM>
 block with a <EM CLASS="Kursiv">
check</EM>
 block referencing a placeholder declared in the <EM CLASS="Kursiv">
doc</EM>
 block of the template. This can be achieved as simple as shown in the following figure:</P>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-1000336"></A>How to simulate cond blocks with check blocks</H5>
<P CLASS="Programm">
<A NAME="pgfId-1000337"></A>&lt;html&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000338"></A>&lt;head&gt;&lt;title&gt;Check block replaces cond block&lt;/title&gt;&lt;/head&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000339"></A>&lt;body&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000340"></A>&lt;!--$ check ADMIN--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000341"></A>	&lt;a href=&quot;#&quot;&gt;[view secret]&lt;/a&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000342"></A>&lt;!--$ end ADMIN--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000343"></A>&lt;table&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000344"></A>	&lt;tr&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000345"></A>		&lt;td width=&quot;100&quot;&gt;&lt;b&gt;Name&lt;/b&gt;&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000346"></A>		&lt;td width=&quot;200&quot;&gt;&lt;b&gt;EMail&lt;/b&gt;&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000347"></A>		&lt;!--$ check ADMIN--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000348"></A>			&lt;td width=&quot;200&quot;&gt;&lt;b&gt;Secret&lt;/b&gt;&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000349"></A>		&lt;!--$ end ADMIN--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000350"></A>	&lt;/tr&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000351"></A>	&lt;!--$ begin entry--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000352"></A>		&lt;tr&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000353"></A>			&lt;td&gt;&lt;!--$ var NAME--&gt;a name&lt;!--$ end NAME--&gt;&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000354"></A>			&lt;td&gt;&lt;!--$ var EMAIL--&gt;hide@address.com</P>
<P CLASS="Programm">
<A NAME="pgfId-1000355"></A>				&lt;!--$ end EMAIL--&gt;&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000356"></A>			&lt;!--$ check doc#ADMIN--&gt;&lt;td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000357"></A>				&lt;!--$ var SECRET--&gt;Secret&lt;!--$ end SECRET--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000358"></A>			&lt;/td&gt;&lt;!--$ end doc#ADMIN--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000359"></A>		&lt;/tr&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000360"></A>	&lt;!--$ end entry--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000361"></A>&lt;/table&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000362"></A>&lt;/body&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1000363"></A>&lt;/html&gt;</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1000364"></A>The figure below shows the control script for the example above, <EM CLASS="Kursiv">
fully-qualified-check.php</EM>
.</P>
</DIV>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-1000365"></A>Control script for the cond block simulator</H5>
<P CLASS="Programm">
<A NAME="pgfId-1000366"></A>&lt;?php</P>
<P CLASS="Programm">
<A NAME="pgfId-1000367"></A>include (&quot;phptempt.php&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1000368"></A>$t = new phptempt (&quot;fully-qualified-check.inc&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1000369"></A>if (isset($admin))</P>
<P CLASS="Programm">
<A NAME="pgfId-1000370"></A>	$t-&gt;addVal (&quot;ADMIN&quot;, 1);</P>
<P CLASS="Programm">
<A NAME="pgfId-1000371"></A>for ($i=0; $i&lt;10; $i++) {</P>
<P CLASS="Programm">
<A NAME="pgfId-1000372"></A>	$t-&gt;begin (&quot;entry&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1000373"></A>	$t-&gt;addVal (&quot;NAME&quot;, &quot;name-$i&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1000374"></A>	$t-&gt;addVal (&quot;EMAIL&quot;, &quot;name-$hide@address.com&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1000375"></A>	if (isset($admin))</P>
<P CLASS="Programm">
<A NAME="pgfId-1000376"></A>	$t-&gt;addVal (&quot;SECRET&quot;, &quot;secret-$i&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1000377"></A>	$t-&gt;end (&quot;entry&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1000378"></A>}</P>
<P CLASS="Programm">
<A NAME="pgfId-1000379"></A>$t-&gt;out();</P>
<P CLASS="Programm">
<A NAME="pgfId-1000380"></A>?&gt;</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1000332"></A>Only when you specify a parameter admin when requesting the script in your browser, that is, when you call the script with the URL <EM CLASS="Kursiv">
fully-qualified-check.php?admin=set</EM>
 for example, it will show you the administrator &quot;secrets&quot;.</P>
</DIV>
</DIV>
</DIV>
<DIV>
<H2 CLASS="Ueberschrift-1">
<A NAME="pgfId-1004161"></A>Recursion</H2>
<P CLASS="Haupttext">
<A NAME="pgfId-1004361"></A>A container block can be referred to from within any of the embedding blocks which is called <EM CLASS="Kursiv">
(block) recursion</EM>
. The purpose of recursion in a <EM CLASS="Kap-">
PhpTempt</EM>
 template is to build documents that display hierarchically nested structures like trees or others, in a convenient way.</P>
<DIV>
<H3 CLASS="Ueberschrift-2">
<A NAME="pgfId-1004370"></A>Syntax</H3>
<P CLASS="Haupttext">
<A NAME="pgfId-1004377"></A>Recursion occurres where a container block is referenced from within itself. The syntax of such a recursive reference is as follows:</P>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-1004384"></A>General syntax of recursive references</H5>
<P CLASS="Programm">
<A NAME="pgfId-1004389"></A>	rec_reference ::= </P>
<P CLASS="Programm">
<A NAME="pgfId-1004394"></A>		&quot;&lt;!--$&quot; &quot;rec&quot; [ qualifiedIdent ] &quot;--&gt;&quot;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004395"></A>			text (no <EM CLASS="Kap-">
PhpTempt</EM>
 tags) that will not be printed</P>
<P CLASS="Programm">
<A NAME="pgfId-1004399"></A>		&quot;&lt;!--$&quot; &quot;end&quot; [ qualifiedIdent ] &quot;--&gt;&quot;</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1005663"></A>For a list of restrictions refer to <A HREF="tutorial.html#40432" CLASS="XRef">See Restrictions on recursion</A>.</P>
</DIV>
</DIV>
<DIV>
<H3 CLASS="Ueberschrift-2">
<A NAME="pgfId-1004400"></A>Depth-first traversal</H3>
<P CLASS="Haupttext">
<A NAME="pgfId-1005078"></A>The listing below shows the standard way in which recursion is employed in <EM CLASS="Kap-">
PhpTempt</EM>
:</P>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-1004422"></A><A NAME="40745"></A>Using recursion in <EM CLASS="Kap-">
PhpTempt</EM>
</H5>
<P CLASS="Programm">
<A NAME="pgfId-1004432"></A>&lt;html&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004433"></A>&lt;head&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004434"></A>&lt;title&gt;Files in directory {FOLDERNAME}&lt;/title&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004435"></A>&lt;/head&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004436"></A>&lt;body&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004438"></A><EM CLASS="Fett">
&lt;!--$ begin dirlist--&gt;</EM>
</P>
<P CLASS="Programm">
<A NAME="pgfId-1004439"></A>	&lt;table&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004440"></A>		&lt;tr&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004441"></A>			&lt;td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004442"></A>				&lt;IMG SRC=&quot;/icons/folder.gif&quot; ALT=&quot;[DIR]&quot;&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004443"></A>			&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004444"></A>			&lt;td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004445"></A>				&lt;b&gt;&lt;!--$ var FOLDERNAME--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004506"></A>					folder name&lt;!--$ end FOLDERNAME--&gt;&lt;/b&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004446"></A>			&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004447"></A>			&lt;td&gt;&amp;nbsp;&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004450"></A>		&lt;/tr&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004451"></A>		&lt;!--$ begin entry--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004452"></A>			&lt;tr&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004453"></A>				&lt;td&gt;&amp;nbsp;&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004454"></A>				&lt;td colspan=&quot;2&quot;&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004455"></A>					&lt;!--$ check NOACCESS--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004456"></A>						&lt;em&gt;Access denied&lt;/em&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004457"></A>					&lt;!--$ end NOACCESS--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004458"></A>					<EM CLASS="Fett">
&lt;!--$ rec doc.dirlist--&gt;</EM>
</P>
<P CLASS="Programm">
<A NAME="pgfId-1004459"></A>						&lt;table bgcolor=&quot;#E0E0E0&quot;&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004460"></A>							&lt;tr&gt;&lt;td&gt;Recursive area, contains</P>
<P CLASS="Programm">
<A NAME="pgfId-1004513"></A>								subdirectory and file lists</P>
<P CLASS="Programm">
<A NAME="pgfId-1004514"></A>							&lt;/td&gt;&lt;/tr&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004461"></A>						&lt;/table&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004462"></A>					<EM CLASS="Fett">
&lt;!--$ end doc.dirlist--&gt;</EM>
</P>
<P CLASS="Programm">
<A NAME="pgfId-1004463"></A>					&lt;!--$ begin textfile--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004464"></A>						&lt;table&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004465"></A>							&lt;td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004466"></A>								&lt;img src=&quot;/icons/text.gif&quot; alt=&quot;[FILE]&quot;&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004467"></A>							&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004468"></A>							&lt;td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004469"></A>								&lt;!--$ var NAME--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004521"></A>									textfile.name&lt;!--$ end NAME--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004470"></A>							&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004471"></A>						&lt;/table&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004472"></A>					&lt;!--$ end textfile--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004473"></A>				&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004474"></A>			&lt;/tr&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004475"></A>		&lt;!--$ end entry--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004476"></A>	&lt;/table&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004477"></A>&lt;!--$ end dirlist--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004479"></A>&lt;/body&gt;&lt;/html&gt;</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1004480"></A>In the listing above, the recursive reference is printed in bold letters, as well as the beginning of the block to which it refers. A recursive reference must always refer to one of its container blocks. In the example, this is the block <EM CLASS="Kursiv">
doc.dirlist</EM>
. The <EM CLASS="Kursiv">
rec</EM>
 tag could also refer to <EM CLASS="Kursiv">
doc.dirlist.entry</EM>
. Because this is the direct superblock, in this case the block identifier could be omitted. You cannot, however, refer to the <EM CLASS="Kursiv">
doc</EM>
 block in a recursive reference.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1004572"></A>The control script for the template in <A HREF="tutorial.html#40745" CLASS="XRef">See Using recursion in PhpTempt</A> is shown below:</P>
</DIV>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-1004581"></A>Using recursion in a control script</H5>
<P CLASS="Programm">
<A NAME="pgfId-1004592"></A>&lt;?php</P>
<P CLASS="Programm">
<A NAME="pgfId-1004599"></A>include (&quot;phptempt.php&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1004601"></A>&nbsp;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004602"></A>function listfolder ($dirpath)</P>
<P CLASS="Programm">
<A NAME="pgfId-1004603"></A>{</P>
<P CLASS="Programm">
<A NAME="pgfId-1004604"></A>	global $t;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004605"></A>	global $con;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004607"></A>	static $count = 0; // debug</P>
<P CLASS="Programm">
<A NAME="pgfId-1004608"></A>&nbsp;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004609"></A>	$t-&gt;begin (&quot;dirlist&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1004611"></A>	$t-&gt;addVal (&quot;FOLDERNAME&quot;, $dirpath);</P>
<P CLASS="Programm">
<A NAME="pgfId-1004612"></A>&nbsp;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004613"></A>	// open folder; if an error occurres on attempt to open folder,</P>
<P CLASS="Programm">
<A NAME="pgfId-1004614"></A>	// then issue a message:</P>
<P CLASS="Programm">
<A NAME="pgfId-1004615"></A>	//</P>
<P CLASS="Programm">
<A NAME="pgfId-1004616"></A>	$dir = @opendir ($dirpath);</P>
<P CLASS="Programm">
<A NAME="pgfId-1004618"></A>	if (is_bool($dir) &amp;&amp; !$dir) {</P>
<P CLASS="Programm">
<A NAME="pgfId-1004619"></A>		$t-&gt;begin (&quot;entry&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1004620"></A>		$t-&gt;addVal (&quot;NOACCESS&quot;, ++$count);</P>
<P CLASS="Programm">
<A NAME="pgfId-1004621"></A>		$t-&gt;end (&quot;entry&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1004622"></A>	}</P>
<P CLASS="Programm">
<A NAME="pgfId-1004623"></A>&nbsp;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004624"></A>	// otherwise, print contents of folder:</P>
<P CLASS="Programm">
<A NAME="pgfId-1004626"></A>	else {</P>
<P CLASS="Programm">
<A NAME="pgfId-1004628"></A>		while ($file = readdir ($dir)) {</P>
<P CLASS="Programm">
<A NAME="pgfId-1004630"></A>			// ignore . and .. entries:</P>
<P CLASS="Programm">
<A NAME="pgfId-1004631"></A>			if ($file==&quot;.&quot; || $file==&quot;..&quot;)</P>
<P CLASS="Programm">
<A NAME="pgfId-1004632"></A>				continue;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004634"></A>&nbsp;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004711"></A>			$filepath = &quot;$dirpath/$file&quot;;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004636"></A>			$t-&gt;begin (&quot;entry&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1004638"></A>			if (is_dir($filepath)) {</P>
<P CLASS="Programm">
<A NAME="pgfId-1004639"></A>				// recursively list subfolder:</P>
<P CLASS="Programm">
<A NAME="pgfId-1004640"></A>				listfolder ($filepath);</P>
<P CLASS="Programm">
<A NAME="pgfId-1004641"></A>			}</P>
<P CLASS="Programm">
<A NAME="pgfId-1004642"></A>			else if (is_file($filepath)) {</P>
<P CLASS="Programm">
<A NAME="pgfId-1004644"></A>				$t-&gt;begin (&quot;textfile&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1004645"></A>				$t-&gt;addVal (&quot;NAME&quot;, $file);</P>
<P CLASS="Programm">
<A NAME="pgfId-1004646"></A>				$t-&gt;end (&quot;textfile&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1004647"></A>			}</P>
<P CLASS="Programm">
<A NAME="pgfId-1004649"></A>			$t-&gt;end (&quot;entry&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1004650"></A>		}</P>
<P CLASS="Programm">
<A NAME="pgfId-1004652"></A>		$dir = closedir ($dir);</P>
<P CLASS="Programm">
<A NAME="pgfId-1004653"></A>	}</P>
<P CLASS="Programm">
<A NAME="pgfId-1004655"></A>	$t-&gt;end (&quot;dirlist&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1004656"></A>}</P>
<P CLASS="Programm">
<A NAME="pgfId-1004724"></A>&nbsp;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004659"></A>$t = new phptempt (&quot;list_dir.inc&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1004661"></A>$rootfolder = &quot;/home&quot;;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004662"></A>$t-&gt;addVal (&quot;FOLDERNAME&quot;, $rootfolder);</P>
<P CLASS="Programm">
<A NAME="pgfId-1004663"></A>&nbsp;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004664"></A>// recursively add contents of project root directory, print template:</P>
<P CLASS="Programm">
<A NAME="pgfId-1004665"></A>listfolder ($rootfolder);</P>
<P CLASS="Programm">
<A NAME="pgfId-1004667"></A>$t-&gt;out();</P>
<P CLASS="Programm">
<A NAME="pgfId-1004669"></A>?&gt;</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1004697"></A>The example is quite complete. The figure below presents a screenshot of the output of this script on a (hypothetical) linux machine.</P>
<OL>
<LI CLASS="Bildunterschrift">
<A NAME="pgfId-1004757"></A><A NAME="61400"></A>Example output of a recursive page</LI>
<IMG SRC="tutorial-5.gif" ALIGN="RIGHT">
</OL>
<P CLASS="Bild-in-Absatz">
<A NAME="pgfId-1004748"></A>As you can see the script outputs the entries in the current directory in any order. As soon as it sees a directory the script descends to that directory and outputs its contents (or issues a message if the operating system refused access to it). This is called <EM CLASS="Kursiv">
depth-first</EM>
 traversal of the directory tree structure.</P>
</DIV>
</DIV>
<DIV>
<H3 CLASS="Ueberschrift-2">
<A NAME="pgfId-1005095"></A>Sorting entries example</H3>
<P CLASS="Haupttext">
<A NAME="pgfId-1004831"></A>For the sake of readability the page should first list the files of the current directory then list the subdirectories (including their contents, again beginning with the files). We will continue to traverse the directory tree in depth-first order but will exploit a property of <EM CLASS="Kap-">
PhpTempt</EM>
 that allows for dividing of the directory contents into files and subdirectories. The listing below shows the template to accomplish this:</P>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-1004858"></A><A NAME="92967"></A>Template for dividing into files and subdirectories</H5>
<P CLASS="Programm">
<A NAME="pgfId-1004865"></A>&lt;html&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004866"></A>&lt;head&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004867"></A>&lt;title&gt;Files in directory {FOLDERNAME}&lt;/title&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004868"></A>&lt;/head&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004869"></A>&lt;body&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004870"></A>&nbsp;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004871"></A>&lt;!--$ begin dirlist--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004872"></A>	&lt;table&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004873"></A>		&lt;tr&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004874"></A>			&lt;td&gt;&lt;img src=&quot;/icons/folder.gif&quot; alt=&quot;[DIR]&quot;&gt;&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004877"></A>			&lt;td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004878"></A>				&lt;b&gt;&lt;!--$ var FOLDERNAME--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004954"></A>					folder name&lt;!--$ end FOLDERNAME--&gt;&lt;/b&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004879"></A>			&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004880"></A>			&lt;td&gt;&amp;nbsp;&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004883"></A>		&lt;/tr&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004884"></A>		&lt;tr&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004885"></A>			&lt;td&gt;&amp;nbsp;&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004886"></A>			&lt;td colspan=&quot;2&quot;&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004887"></A>				&lt;!--$ check NOACCESS--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004888"></A>					&lt;em&gt;Access denied&lt;/em&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004889"></A>				&lt;!--$ end NOACCESS--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004890"></A>				&lt;!--$ begin textfile--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004891"></A>					&lt;table&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004892"></A>						&lt;td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004893"></A>							&lt;img src=&quot;/icons/text.gif&quot; alt=&quot;[FILE]&quot;&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004894"></A>						&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004895"></A>						&lt;td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004896"></A>							&lt;!--$ var NAME--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004965"></A>								textfile.name&lt;!--$ end NAME--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004897"></A>						&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004898"></A>					&lt;/table&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004899"></A>				&lt;!--$ end textfile--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004900"></A>				&lt;!--$ rec--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004901"></A>					&lt;table bgcolor=&quot;#E0E0E0&quot;&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004902"></A>						&lt;tr&gt;&lt;td&gt;Recursive area, contains subdirectory</P>
<P CLASS="Programm">
<A NAME="pgfId-1004966"></A>							and file lists&lt;/td&gt;&lt;/tr&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004903"></A>					&lt;/table&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004904"></A>				&lt;!--$ end--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004905"></A>			&lt;/td&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004906"></A>		&lt;/tr&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004907"></A>	&lt;/table&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004908"></A>&lt;!--$ end dirlist--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004910"></A>&lt;/body&gt;&lt;/html&gt;</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1004911"></A>The listing below shows the control script:</P>
</DIV>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-1004973"></A><A NAME="58903"></A>Control script for the divider template above</H5>
<P CLASS="Programm">
<A NAME="pgfId-1004984"></A>&lt;?php</P>
<P CLASS="Programm">
<A NAME="pgfId-1004986"></A>include (&quot;phptempt.php&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1004988"></A>&nbsp;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004989"></A>function listfolder ($dirpath)</P>
<P CLASS="Programm">
<A NAME="pgfId-1004990"></A>{</P>
<P CLASS="Programm">
<A NAME="pgfId-1004991"></A>	global $t;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004992"></A>	global $con;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004994"></A>	static $count = 0; // debug</P>
<P CLASS="Programm">
<A NAME="pgfId-1004995"></A>&nbsp;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004996"></A>	$t-&gt;begin (&quot;dirlist&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1004998"></A>	$t-&gt;addVal (&quot;FOLDERNAME&quot;, $dirpath);</P>
<P CLASS="Programm">
<A NAME="pgfId-1005000"></A>	// open folder; if an error occurres on attempt to open folder,</P>
<P CLASS="Programm">
<A NAME="pgfId-1005001"></A>	// then issue a message:</P>
<P CLASS="Programm">
<A NAME="pgfId-1005003"></A>	$dir = @opendir ($dirpath);</P>
<P CLASS="Programm">
<A NAME="pgfId-1005005"></A>	if (is_bool($dir) &amp;&amp; !$dir) {</P>
<P CLASS="Programm">
<A NAME="pgfId-1005006"></A>		$t-&gt;addVal (&quot;NOACCESS&quot;, ++$count);</P>
<P CLASS="Programm">
<A NAME="pgfId-1005007"></A>	}</P>
<P CLASS="Programm">
<A NAME="pgfId-1005009"></A>	// otherwise, print contents of folder:</P>
<P CLASS="Programm">
<A NAME="pgfId-1005011"></A>	else {</P>
<P CLASS="Programm">
<A NAME="pgfId-1005013"></A>		while ($file = readdir ($dir)) {</P>
<P CLASS="Programm">
<A NAME="pgfId-1005015"></A>		// ignore . and .. entries:</P>
<P CLASS="Programm">
<A NAME="pgfId-1005016"></A>		if ($file==&quot;.&quot; || $file==&quot;..&quot;)</P>
<P CLASS="Programm">
<A NAME="pgfId-1005017"></A>			continue;</P>
<P CLASS="Programm">
<A NAME="pgfId-1005019"></A>		$filepath = &quot;$dirpath/$file&quot;;</P>
<P CLASS="Programm">
<A NAME="pgfId-1005021"></A>		if (is_dir($filepath)) {</P>
<P CLASS="Programm">
<A NAME="pgfId-1005022"></A>			// recursively list subfolder:</P>
<P CLASS="Programm">
<A NAME="pgfId-1005023"></A>			listfolder ($filepath);</P>
<P CLASS="Programm">
<A NAME="pgfId-1005024"></A>		}</P>
<P CLASS="Programm">
<A NAME="pgfId-1005025"></A>		else if (is_file($filepath)) {</P>
<P CLASS="Programm">
<A NAME="pgfId-1005026"></A>			// print textfile:</P>
<P CLASS="Programm">
<A NAME="pgfId-1005027"></A>			$t-&gt;begin (&quot;textfile&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1005028"></A>			$t-&gt;addVal (&quot;NAME&quot;, $file);</P>
<P CLASS="Programm">
<A NAME="pgfId-1005029"></A>			$t-&gt;end (&quot;textfile&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1005030"></A>		}</P>
<P CLASS="Programm">
<A NAME="pgfId-1005031"></A>	}</P>
<P CLASS="Programm">
<A NAME="pgfId-1005033"></A>	$dir = closedir ($dir);</P>
<P CLASS="Programm">
<A NAME="pgfId-1005034"></A>	}</P>
<P CLASS="Programm">
<A NAME="pgfId-1005036"></A>	$t-&gt;end (&quot;dirlist&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1005037"></A>}</P>
<P CLASS="Programm">
<A NAME="pgfId-1005071"></A>&nbsp;</P>
<P CLASS="Programm">
<A NAME="pgfId-1005040"></A>$t = new phptempt (&quot;list_dir_div.inc&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1005042"></A>$rootfolder = &quot;/var/projects/phptempt&quot;;</P>
<P CLASS="Programm">
<A NAME="pgfId-1005043"></A>$t-&gt;addVal (&quot;FOLDERNAME&quot;, $rootfolder);</P>
<P CLASS="Programm">
<A NAME="pgfId-1005044"></A>&nbsp;</P>
<P CLASS="Programm">
<A NAME="pgfId-1005045"></A>// recursively add contents of project root directory, print template:</P>
<P CLASS="Programm">
<A NAME="pgfId-1005046"></A>listfolder ($rootfolder);</P>
<P CLASS="Programm">
<A NAME="pgfId-1005048"></A>$t-&gt;out();</P>
<P CLASS="Programm">
<A NAME="pgfId-1005049"></A>&nbsp;</P>
<P CLASS="Programm">
<A NAME="pgfId-1004979"></A>?&gt;</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1004912"></A>The script collects all files of the current directory in the <EM CLASS="Kursiv">
textfile</EM>
 block of the template and all its subdirectories in the recursive block that will be created in place of the recursive reference.</P>
</DIV>
</DIV>
<DIV>
<H3 CLASS="Ueberschrift-2">
<A NAME="pgfId-1005099"></A>Unrolling recursion</H3>
<P CLASS="Haupttext">
<A NAME="pgfId-1005102"></A>To understand how recursion works in <EM CLASS="Kap-">
PhpTempt</EM>
 it might be useful to eliminate recursive calls to the <EM CLASS="Kursiv">
listfolder</EM>
 function of the script depicted in <A HREF="tutorial.html#58903" CLASS="XRef">See Control script for the divider template above</A> and to replace these with a sequence of calls to the <EM CLASS="Kursiv">
begin</EM>
 and <EM CLASS="Kursiv">
end</EM>
 methods of the <EM CLASS="Kap-">
PhpTempt</EM>
 class such that the script prints the structure of <A HREF="tutorial.html#61400" CLASS="XRef">See Example output of a recursive page</A>. The figure below shows the resulting script that controls the template of <A HREF="tutorial.html#92967" CLASS="XRef">See Template for dividing into files and subdirectories</A>.</P>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-1005160"></A>Unrolling recursion</H5>
<OL>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005223"></A>&lt;?php</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005224"></A>&nbsp;</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005225"></A>include (&quot;phptempt.php&quot;);</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005226"></A>$t = new phptempt (&quot;list_dir_div.inc&quot;);</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005227"></A>&nbsp;</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005228"></A>$t-&gt;begin (&quot;<EM CLASS="Fett">
dirlist</EM>
&quot;);</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005229"></A>$t-&gt;addVal (&quot;FOLDERNAME&quot;, &quot;/home&quot;);</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005231"></A>$t-&gt;begin (&quot;textfile&quot;);</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005232"></A>$t-&gt;addVal (&quot;NAME&quot;, &quot;user.txt&quot;);</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005233"></A>$t-&gt;end (&quot;textfile&quot;);</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005234"></A>$t-&gt;begin (&quot;textfile&quot;);</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005235"></A>$t-&gt;addVal (&quot;NAME&quot;, &quot;readme&quot;);</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005236"></A>$t-&gt;end (&quot;textfile&quot;);</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005238"></A><A NAME="61045"></A>	$t-&gt;begin (&quot;<EM CLASS="Fett">
dirlist</EM>
&quot;);</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005239"></A>	$t-&gt;addVal (&quot;FOLDERNAME&quot;, &quot;/home/christine&quot;);</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005241"></A>	$t-&gt;addVal (&quot;NOACCESS&quot;, true);</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005243"></A>	$t-&gt;end (&quot;<EM CLASS="Fett">
dirlist</EM>
&quot;);</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005245"></A>	$t-&gt;begin (&quot;<EM CLASS="Fett">
dirlist</EM>
&quot;);</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005246"></A>	$t-&gt;addVal (&quot;FOLDERNAME&quot;, &quot;/home/claus&quot;);</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005248"></A><A NAME="85451"></A>		$t-&gt;begin (&quot;<EM CLASS="Fett">
dirlist</EM>
&quot;);</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005249"></A>		$t-&gt;addVal (&quot;FOLDERNAME&quot;, &quot;/home/claus/cpp&quot;);</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005251"></A>		$t-&gt;begin (&quot;textfile&quot;);</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005252"></A>		$t-&gt;addVal (&quot;NAME&quot;, &quot;fold.cpp&quot;);</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005253"></A>		$t-&gt;end (&quot;textfile&quot;);</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005254"></A>		$t-&gt;begin (&quot;textfile&quot;);</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005255"></A>		$t-&gt;addVal (&quot;NAME&quot;, &quot;fold.h&quot;);</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005256"></A>		$t-&gt;end (&quot;textfile&quot;);</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005258"></A>		$t-&gt;end (&quot;<EM CLASS="Fett">
dirlist</EM>
&quot;);</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005260"></A>	$t-&gt;begin (&quot;textfile&quot;);</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005261"></A>	$t-&gt;addVal (&quot;NAME&quot;, &quot;.exrc&quot;);</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005262"></A>	$t-&gt;end (&quot;textfile&quot;);</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005264"></A>	$t-&gt;end (&quot;<EM CLASS="Fett">
dirlist</EM>
&quot;);</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005266"></A>	$t-&gt;begin (&quot;<EM CLASS="Fett">
dirlist</EM>
&quot;);</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005268"></A>	$t-&gt;addVal (&quot;FOLDERNAME&quot;, &quot;/home/hans&quot;);</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005269"></A>	$t-&gt;begin (&quot;textfile&quot;);</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005270"></A>	$t-&gt;addVal (&quot;NAME&quot;, &quot;.exrc&quot;);</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005271"></A>	$t-&gt;end (&quot;textfile&quot;);</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005273"></A>	$t-&gt;end (&quot;<EM CLASS="Fett">
dirlist</EM>
&quot;);</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005275"></A>$t-&gt;end (&quot;<EM CLASS="Fett">
dirlist</EM>
&quot;);</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005276"></A>&nbsp;</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005277"></A>$t-&gt;out();</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005278"></A>&nbsp;</LI>
<LI CLASS="Programm-numeriert">
<A NAME="pgfId-1005181"></A>?&gt;</LI>
</OL>
<P CLASS="Haupttext">
<A NAME="pgfId-1005199"></A>To reflect the recursive structure of the original script, I indented the unrolled script according to the recursion level.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1005364"></A>The template from <A HREF="tutorial.html#92967" CLASS="XRef">See Template for dividing into files and subdirectories</A> itself defines only the blocks <EM CLASS="Kursiv">
doc.dirlist</EM>
 and <EM CLASS="Kursiv">
doc.dirlist.textfile</EM>
 explicitly. As for all templates, the <EM CLASS="Kursiv">
doc</EM>
 block is implicitly defined. Since the template also contains a <EM CLASS="Kursiv">
rec</EM>
 tag without block identifier which automatically refers to the direct container block, <EM CLASS="Kursiv">
doc.dirlist</EM>
, an infinite number of blocks <EM CLASS="Kursiv">
doc.dirlist.dirlist</EM>
, <EM CLASS="Kursiv">
doc.dirlist.dirlist.textfile</EM>
, <EM CLASS="Kursiv">
doc.dirlist.dirlist.dirlist</EM>
, <EM CLASS="Kursiv">
doc.dirlist.dirlist.dirlist.textfile</EM>
, etc. will be available to the controlling script.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1005601"></A>The call to the <EM CLASS="Kursiv">
begin</EM>
 method of the <EM CLASS="Kap-">
PhpTempt</EM>
 instance in <A HREF="tutorial.html#61045" CLASS="XRef">See $t-&gt;begin (&quot;dirlist&quot;);</A> replaces the recursive reference in block <EM CLASS="Kursiv">
doc.dirlist</EM>
 with a copy of this block and thus defines block <EM CLASS="Kursiv">
doc.dirlist.dirlist</EM>
 as well as the embedded block <EM CLASS="Kursiv">
doc.dirlist.dirlist.textfile</EM>
 and placeholders <EM CLASS="Kursiv">
doc.dirlist.dirlist#FOLDERNAME</EM>
, <EM CLASS="Kursiv">
doc.dirlist.dirlist#NOACCESS</EM>
 and <EM CLASS="Kursiv">
doc.dirlist.dirlist.textfile#NAME</EM>
. Note that the block <EM CLASS="Kursiv">
doc.dirlist.dirlist</EM>
 now contains the recursive reference to <EM CLASS="Kursiv">
doc.dirlist</EM>
. This recursive reference will be replaced by a block copy named <EM CLASS="Kursiv">
doc.dirlist.dirlist.dirlist</EM>
 in <A HREF="tutorial.html#85451" CLASS="XRef">See $t-&gt;begin (&quot;dirlist&quot;);</A> where the next level of recursion is started.</P>
</DIV>
</DIV>
<DIV>
<H3 CLASS="Ueberschrift-2">
<A NAME="pgfId-1005643"></A><A NAME="40432"></A>Restrictions on recursion</H3>
<P CLASS="Haupttext">
<A NAME="pgfId-1005647"></A>There are few restrictions to recursion that concern the use of recursive references:</P>
<UL>
<LI CLASS="Markiert">
<A NAME="pgfId-1005650"></A>Each block may contain only one recursive reference. Otherwise, <EM CLASS="Kap-">
PhpTempt</EM>
 would not be able to determine which of the references to replace by a recursive block.</LI>
<LI CLASS="Markiert">
<A NAME="pgfId-1006726"></A>A <EM CLASS="Kursiv">
rec</EM>
 tag cannot refer to a block other than an embedding block. If it references the direct embedding block, the block qualifier may be omitted. Otherwise, the qualified name of the block referenced in the <EM CLASS="Kursiv">
rec</EM>
 tag must be a prefix of the fully qualified name of the block that contains the tag.</LI>
</UL>
<P CLASS="Haupttext-eingerueckt">
<A NAME="pgfId-1006731"></A>An example for this <EM CLASS="Kursiv">
prefix rule</EM>
 is given in <A HREF="tutorial.html#31481" CLASS="XRef">See Prefix rule</A> below. The recursive reference (printed in bold) refers to the block <EM CLASS="Kursiv">
doc.list</EM>
. Since this is a prefix of the name of the container block for the reference, <EM CLASS="Kursiv">
doc.list.entry</EM>
, the prefix rule holds as would a reference to <EM CLASS="Kursiv">
doc.list.entry</EM>
 or even <EM CLASS="Kursiv">
doc</EM>
. By contrast, a reference to <EM CLASS="Kursiv">
doc.header</EM>
 is not valid. Here, the prefix rule would be violated.</P>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-1008351"></A><A NAME="31481"></A>Prefix rule</H5>
<P CLASS="Programm">
<A NAME="pgfId-1008367"></A>		&lt;!--$ begin header--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1008375"></A>			Header for {LISTNAME}.</P>
<P CLASS="Programm">
<A NAME="pgfId-1008374"></A>		&lt;!--$ end header--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1008373"></A>		&lt;!--$ begin list--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1008372"></A>			... some HTML code</P>
<P CLASS="Programm">
<A NAME="pgfId-1008377"></A>			&lt;!--$ begin entry--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1008376"></A>				&lt;!--$ <EM CLASS="Fett">
rec</EM>
 doc.list--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1008381"></A>					recursive part (this text will not be visible in the</P>
<P CLASS="Programm">
<A NAME="pgfId-1008382"></A>						output of the template)</P>
<P CLASS="Programm">
<A NAME="pgfId-1008383"></A>				&lt;!--$ <EM CLASS="Fett">
end</EM>
 doc.list--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1008414"></A>			... some more HTML code</P>
<P CLASS="Programm">
<A NAME="pgfId-1008371"></A>		&lt;!--$ end list--&gt;</P>
<UL>
<LI CLASS="Markiert">
<A NAME="pgfId-1005698"></A>The <EM CLASS="Kursiv">
doc</EM>
 block (<A HREF="tutorial.html#16061" CLASS="XRef">See The document root block</A>) can be the target of a recursive reference. Since this block usually contains the <EM CLASS="Kursiv">
html</EM>
-, <EM CLASS="Kursiv">
head</EM>
- and <EM CLASS="Kursiv">
body</EM>
-tags, referencing it is thoroughly discouraged.</LI>
</UL>
</DIV>
</DIV>
<DIV>
<H3 CLASS="Ueberschrift-2">
<A NAME="pgfId-1012178"></A><A NAME="65722"></A>Relative paths in recursive templates</H3>
<P CLASS="Haupttext">
<A NAME="pgfId-1012182"></A>Reuse of recursive templates necessitates employment of placeholders with relative paths. Consider the following template file:</P>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-1013851"></A>Absolute paths in a recursive template</H5>
<P CLASS="Programm">
<A NAME="pgfId-1013866"></A>&lt;!--$ begin recBlock--&gt;&lt;!--$ begin list1--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1013867"></A>	{NAME}: {NUMBER}&lt;!--$ end list1--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1013868"></A>&nbsp;</P>
<P CLASS="Programm">
<A NAME="pgfId-1013869"></A>	&lt;!--$ begin list2--&gt;&lt;!--$ check doc.recBlock.list1#NAME--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1013870"></A>		{doc.recBlock.list1#NAME} has been set:</P>
<P CLASS="Programm">
<A NAME="pgfId-1013871"></A>		{doc.recBlock.list1#NAME}: {ABBREV}&lt;!--$</P>
<P CLASS="Programm">
<A NAME="pgfId-1013879"></A>			end--&gt;&lt;!--$ check ! doc.recBlock.list1#NAME--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1013872"></A>		No value for doc.recBlock.list1#NAME has been set&lt;!--$ </P>
<P CLASS="Programm">
<A NAME="pgfId-1013882"></A>			end--&gt;&lt;!--$ end list2--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1013873"></A>&nbsp;</P>
<P CLASS="Programm">
<A NAME="pgfId-1013874"></A>	&lt;!--$ rec doc.recBlock--&gt;recursive block</P>
<P CLASS="Programm">
<A NAME="pgfId-1013885"></A>	&lt;!--$ end doc.recBlock--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1013856"></A>&lt;!--$ end recBlock--&gt;</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1013861"></A>This template contains placeholder references with absolute path embedded in a recursive block. Using the Java program below,</P>
</DIV>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-1013886"></A><A NAME="14465"></A>Java program for the template file with absolute path in the placeholder</H5>
<P CLASS="Programm">
<A NAME="pgfId-1013910"></A>import phptempt.*;</P>
<P CLASS="Programm">
<A NAME="pgfId-1013912"></A>public class otherblock {</P>
<P CLASS="Programm">
<A NAME="pgfId-1013914"></A>	public static void main (String[] args)</P>
<P CLASS="Programm">
<A NAME="pgfId-1013915"></A>	{</P>
<P CLASS="Programm">
<A NAME="pgfId-1013916"></A>		Phptempt t = new Phptempt (&quot;otherblock_inc&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1013918"></A>		t.begin (&quot;recBlock&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1013920"></A>		for (int i=0; i&lt;2; i++) {</P>
<P CLASS="Programm">
<A NAME="pgfId-1013922"></A>			t.begin (&quot;list1&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1013923"></A>			t.addVal (&quot;NAME&quot;, &quot;&quot;+(char)(i+65));</P>
<P CLASS="Programm">
<A NAME="pgfId-1013924"></A>			t.addVal (&quot;NUMBER&quot;, Integer.toString(i));</P>
<P CLASS="Programm">
<A NAME="pgfId-1013925"></A>			t.end (&quot;list1&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1013926"></A>		}</P>
<P CLASS="Programm">
<A NAME="pgfId-1013928"></A>		for (int i=0; i&lt;3; i++) {</P>
<P CLASS="Programm">
<A NAME="pgfId-1013930"></A>			t.begin (&quot;list2&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1013931"></A>			t.addVal (&quot;ABBREV&quot;, &quot;Ko&quot;+i);</P>
<P CLASS="Programm">
<A NAME="pgfId-1013932"></A>			t.end (&quot;list2&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1013933"></A>		}</P>
<P CLASS="Programm">
<A NAME="pgfId-1013935"></A>	// recursive:</P>
<P CLASS="Programm">
<A NAME="pgfId-1013936"></A>		t.begin (&quot;recBlock&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1013940"></A>		for (int i=2; i&lt;5; i++) {</P>
<P CLASS="Programm">
<A NAME="pgfId-1013942"></A>			t.begin (&quot;list1&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1013943"></A>			t.addVal (&quot;NAME&quot;, &quot;&quot;+(char)(i+65));</P>
<P CLASS="Programm">
<A NAME="pgfId-1013944"></A>			t.addVal (&quot;NUMBER&quot;, Integer.toString(i));</P>
<P CLASS="Programm">
<A NAME="pgfId-1013945"></A>			t.end (&quot;list1&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1013946"></A>		}</P>
<P CLASS="Programm">
<A NAME="pgfId-1013948"></A>		for (int i=2; i&lt;5; i++) {</P>
<P CLASS="Programm">
<A NAME="pgfId-1013950"></A>			t.begin (&quot;list2&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1013951"></A>			t.addVal (&quot;ABBREV&quot;, &quot;Ko&quot;+i);</P>
<P CLASS="Programm">
<A NAME="pgfId-1013952"></A>			t.end (&quot;list2&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1013953"></A>		}</P>
<P CLASS="Programm">
<A NAME="pgfId-1013955"></A>		t.end (&quot;recBlock&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1013958"></A>	// end recursive</P>
<P CLASS="Programm">
<A NAME="pgfId-1013960"></A>		t.end (&quot;recBlock&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1013962"></A>		t.write (&quot;otherblock.out&quot;);</P>
<P CLASS="Programm">
<A NAME="pgfId-1013963"></A>	}</P>
<P CLASS="Programm">
<A NAME="pgfId-1013891"></A>}</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1013896"></A>we obtain an output that I find very counter-intuitive:</P>
</DIV>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-1013908"></A>Output of the preceding Java program</H5>
<P CLASS="Programm">
<A NAME="pgfId-1014043"></A>	A: 0</P>
<P CLASS="Programm">
<A NAME="pgfId-1014044"></A>	B: 1</P>
<P CLASS="Programm">
<A NAME="pgfId-1014087"></A>		A has been set:</P>
<P CLASS="Programm">
<A NAME="pgfId-1014048"></A>		A: Ko0</P>
<P CLASS="Programm">
<A NAME="pgfId-1014049"></A>		B has been set:</P>
<P CLASS="Programm">
<A NAME="pgfId-1014050"></A>		B: Ko1</P>
<P CLASS="Programm">
<A NAME="pgfId-1014051"></A>		No value for doc.recBlock.list1#NAME has been set</P>
<P CLASS="Programm">
<A NAME="pgfId-1014092"></A>	C: 2</P>
<P CLASS="Programm">
<A NAME="pgfId-1014055"></A>	D: 3</P>
<P CLASS="Programm">
<A NAME="pgfId-1014056"></A>	E: 4</P>
<P CLASS="Programm">
<A NAME="pgfId-1014095"></A>		A has been set:</P>
<P CLASS="Programm">
<A NAME="pgfId-1014060"></A>		A: Ko2</P>
<P CLASS="Programm">
<A NAME="pgfId-1014061"></A>		A has been set:</P>
<P CLASS="Programm">
<A NAME="pgfId-1014062"></A>		A: Ko3</P>
<P CLASS="Programm">
<A NAME="pgfId-1014063"></A>		A has been set:</P>
<P CLASS="Programm">
<A NAME="pgfId-1014064"></A>		A: Ko4</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1014033"></A>To understand why in the recursive block <EM CLASS="Kap-">
PhpTempt</EM>
 always outputs the value &quot;A&quot;, we proceed as in <A HREF="tutorial.html#74774" CLASS="XRef">See References to the parent block</A> and count the number of calls to the <EM CLASS="Kursiv">
begin</EM>
 method for each block in the template during execution of the Java program:</P>
</DIV>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-1014126"></A>Number of calls to method begin for each template block</H5>
<P CLASS="Programm">
<A NAME="pgfId-1014134"></A>[1]		recBlock</P>
<P CLASS="Programm">
<A NAME="pgfId-1014159"></A>[1,1]			list1</P>
<P CLASS="Programm">
<A NAME="pgfId-1014158"></A>				A: 0</P>
<P CLASS="Programm">
<A NAME="pgfId-1014184"></A>[1,2]			list1</P>
<P CLASS="Programm">
<A NAME="pgfId-1014135"></A>				B: 1</P>
<P CLASS="Programm">
<A NAME="pgfId-1014160"></A>[1,1]			list2</P>
<P CLASS="Programm">
<A NAME="pgfId-1014136"></A>				A has been set:</P>
<P CLASS="Programm">
<A NAME="pgfId-1014137"></A>				A: Ko0</P>
<P CLASS="Programm">
<A NAME="pgfId-1014190"></A>[1,2]			list2</P>
<P CLASS="Programm">
<A NAME="pgfId-1014138"></A>				B has been set:</P>
<P CLASS="Programm">
<A NAME="pgfId-1014139"></A>				B: Ko1</P>
<P CLASS="Programm">
<A NAME="pgfId-1014194"></A>[1,3]			list2</P>
<P CLASS="Programm">
<A NAME="pgfId-1014140"></A>				No value for doc.recBlock.list1#NAME has been set</P>
<P CLASS="Programm">
<A NAME="pgfId-1014161"></A>[1,1]			recBlock</P>
<P CLASS="Programm">
<A NAME="pgfId-1014182"></A>[1,1,1]				list1</P>
<P CLASS="Programm">
<A NAME="pgfId-1014141"></A>					C: 2</P>
<P CLASS="Programm">
<A NAME="pgfId-1014208"></A>[1,1,2]				list1</P>
<P CLASS="Programm">
<A NAME="pgfId-1014142"></A>					D: 3</P>
<P CLASS="Programm">
<A NAME="pgfId-1014212"></A>[1,1,3]				list1</P>
<P CLASS="Programm">
<A NAME="pgfId-1014143"></A>					E: 4</P>
<P CLASS="Programm">
<A NAME="pgfId-1014263"></A>[1,1,1]				list 2</P>
<P CLASS="Programm">
<A NAME="pgfId-1014144"></A>					A has been set:</P>
<P CLASS="Programm">
<A NAME="pgfId-1014145"></A>					A: Ko2</P>
<P CLASS="Programm">
<A NAME="pgfId-1014265"></A>[1,1,2]				list 2</P>
<P CLASS="Programm">
<A NAME="pgfId-1014146"></A>					A has been set:</P>
<P CLASS="Programm">
<A NAME="pgfId-1014147"></A>					A: Ko3</P>
<P CLASS="Programm">
<A NAME="pgfId-1014269"></A>[1,1,3]				list 2</P>
<P CLASS="Programm">
<A NAME="pgfId-1014148"></A>					A has been set:</P>
<P CLASS="Programm">
<A NAME="pgfId-1014149"></A>					A: Ko4</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1014154"></A>As you can see from this listing, all the references to <EM CLASS="Kursiv">
doc.recBlock.list1#NAME</EM>
 go to the placeholder <EM CLASS="Kursiv">
NAME</EM>
 in the first iteration of the <EM CLASS="Kursiv">
block doc.recBlock.list1</EM>
 which is not at all what we wanted.</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1014286"></A>Use of a relative path in the placeholder, that is use of <EM CLASS="Kursiv">
^recBlock.list1#NAME</EM>
, resolves this:</P>
</DIV>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-1014289"></A><A NAME="72373"></A>Use of relative paths in placeholder references</H5>
<P CLASS="Programm">
<A NAME="pgfId-1014321"></A>&lt;!--$ begin recBlock--&gt;&lt;!--$ begin list1--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1014322"></A>	{NAME}: {NUMBER}&lt;!--$ end list1--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1014323"></A>&nbsp;</P>
<P CLASS="Programm">
<A NAME="pgfId-1014324"></A>	&lt;!--$ begin list2--&gt;&lt;!--$ check doc.recBlock.list1#NAME--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1014325"></A>		{^recBlock.list1#NAME} has been set:</P>
<P CLASS="Programm">
<A NAME="pgfId-1014326"></A>		{^recBlock.list1#NAME}: {ABBREV}&lt;!--$ end--&gt;&lt;!--$ check</P>
<P CLASS="Programm">
<A NAME="pgfId-1014339"></A>			! ^recBlock.list1#NAME--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1014327"></A>		No value for ^recBlock.list1#NAME has been set&lt;!--$</P>
<P CLASS="Programm">
<A NAME="pgfId-1014338"></A>			end--&gt;&lt;!--$ end list2--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1014328"></A>&nbsp;</P>
<P CLASS="Programm">
<A NAME="pgfId-1014329"></A>	&lt;!--$ rec ^.recBlock--&gt;recursive block</P>
<P CLASS="Programm">
<A NAME="pgfId-1014337"></A>	&lt;!--$ end ^.recBlock--&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-1014301"></A>&lt;!--$ end recBlock--&gt;</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1014312"></A>The Java program depicted in <A HREF="tutorial.html#14465" CLASS="XRef">See Java program for the template file with absolute path in the placeholder</A> when using the new template file above finally shows the expected output, that is:</P>
</DIV>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-1014386"></A>Output of the Java program using the new template</H5>
<P CLASS="Programm">
<A NAME="pgfId-1014404"></A>&nbsp;</P>
<P CLASS="Programm">
<A NAME="pgfId-1014405"></A>	A: 0</P>
<P CLASS="Programm">
<A NAME="pgfId-1014406"></A>	B: 1</P>
<P CLASS="Programm">
<A NAME="pgfId-1014409"></A>		A has been set:</P>
<P CLASS="Programm">
<A NAME="pgfId-1014410"></A>		A: Ko0</P>
<P CLASS="Programm">
<A NAME="pgfId-1014411"></A>		B has been set:</P>
<P CLASS="Programm">
<A NAME="pgfId-1014412"></A>		B: Ko1</P>
<P CLASS="Programm">
<A NAME="pgfId-1014413"></A>		No value for ^recBlock.list1#NAME has been set</P>
<P CLASS="Programm">
<A NAME="pgfId-1014416"></A>	C: 2</P>
<P CLASS="Programm">
<A NAME="pgfId-1014417"></A>	D: 3</P>
<P CLASS="Programm">
<A NAME="pgfId-1014418"></A>	E: 4</P>
<P CLASS="Programm">
<A NAME="pgfId-1014421"></A>		C has been set:</P>
<P CLASS="Programm">
<A NAME="pgfId-1014422"></A>		C: Ko2</P>
<P CLASS="Programm">
<A NAME="pgfId-1014423"></A>		D has been set:</P>
<P CLASS="Programm">
<A NAME="pgfId-1014424"></A>		D: Ko3</P>
<P CLASS="Programm">
<A NAME="pgfId-1014425"></A>		E has been set:</P>
<P CLASS="Programm">
<A NAME="pgfId-1014426"></A>		E: Ko4</P>
<P CLASS="Haupttext">
<A NAME="pgfId-1014593"></A>Please note also the relative path of the block in the <EM CLASS="Kursiv">
rec</EM>
 tag (<A HREF="tutorial.html#72373" CLASS="XRef">See Use of relative paths in placeholder references</A>). Using relative paths you may simply &quot;copy-and-paste&quot; portions of a template file to another template without the need to change the placeholder or block names (<A HREF="tutorial.html#36844" CLASS="XRef">See References to placeholders</A>).</P>
</DIV>
</DIV>
</DIV>
<DIV>
<H2 CLASS="Ueberschrift-1">
<A NAME="pgfId-997260"></A>Known Bugs and missing Features</H2>
<DIV>
<H3 CLASS="Ueberschrift-2">
<A NAME="pgfId-997305"></A><A NAME="22822"></A>Features</H3>
<P CLASS="Haupttext">
<A NAME="pgfId-999307"></A>There are some features that I would like to add to <EM CLASS="Kap-">
PhpTempt</EM>
 (in the order of priority that I give to them):</P>
<UL>
<LI CLASS="Markiert">
<A NAME="pgfId-1001216"></A>Reimplement <EM CLASS="Kap-">
PhpTempt</EM>
 using <EM CLASS="Kap-">
PhpTempt</EM>
. This is a precondition for the implementation of the following feature:</LI>
<LI CLASS="Markiert">
<A NAME="pgfId-1001229"></A>Port <EM CLASS="Kap-">
PhpTempt</EM>
 classes to C++. Add mechanism to produce C++ code from the template files. Compiled C/C++ code executes about 10 times faster than Java code.</LI>
<LI CLASS="Markiert">
<A NAME="pgfId-1001256"></A>Add command line options to enclose <EM CLASS="Kap-">
PhpTempt</EM>
 commands in template files using some alternatives, for example /**$ ... */ or //$ .. . The HTML-like tags used for the moment look really strange to me.</LI>
<LI CLASS="Markiert">
<A NAME="pgfId-1001264"></A>Implement placeholder references wth relative path in PHP. The parser will complain if you try to generate PHP code from a template that contains relative placeholder references.</LI>
<LI CLASS="Markiert">
<A NAME="pgfId-1001275"></A>Add new command line option that sets a random large integer as the name of each element. This is similar to the command line option that sets the name of each element to its fully qualified path. An option that merly serves debugging purposes.</LI>
<LI CLASS="Markiert">
<A NAME="pgfId-1001280"></A>Add compiling instructions as comments to the preprocessed Java template file. If some day you find a Java or PHP code in one of your directories, you would perhaps like to know what it once was good for and how to make it work?</LI>
</UL>
</DIV>
<DIV>
<H3 CLASS="Ueberschrift-2">
<A NAME="pgfId-997304"></A><A NAME="35548"></A>Known Bugs</H3>
<P CLASS="Haupttext">
<A NAME="pgfId-1000172"></A>There are also some bugs that I have recognized but cannot put my fingers on exactly to find a solution:</P>
<UL>
<LI CLASS="Markiert">
<A NAME="pgfId-1000169"></A>Blocks containing conditional check blocks and placeholders are not printed if only the variable declared in the check block is set. The block should be printed in this case.</LI>
<LI CLASS="Markiert">
<A NAME="pgfId-997568"></A>Nested blocks with name <EM CLASS="Kursiv">
doc</EM>
 are possible, provided that they don't have the document root block as parent. A template such as the one defined below would be ineffective and useless:</LI>
</UL>
<DIV>
<IMG SRC="tutorial-6.gif">
</DIV>
<DIV>
<H5 CLASS="Bildunterschrift-seitlich">
<A NAME="pgfId-997569"></A>Bug: Nested block with name &quot;doc&quot;</H5>
<P CLASS="Programm">
<A NAME="pgfId-997575"></A>		&lt;html&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-997582"></A>		&lt;body&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-997583"></A>		&lt;!--$ begin doc --&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-997585"></A>			&lt;!-- more HTML code --&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-997586"></A>			This is a {PLACEHOLDER}.</P>
<P CLASS="Programm">
<A NAME="pgfId-997589"></A>			&lt;!-- more HTML code --&gt;</P>
<P CLASS="Programm">
<A NAME="pgfId-997584"></A>		&lt;!--$ end doc --&gt;</P>
<P CLASS="Haupttext-eingerueckt">
<A NAME="pgfId-997598"></A>The problem with this template is that</P>
<OL>
<LI CLASS="Numeriert-n-1">
<A NAME="pgfId-997602"></A>A call to the <EM CLASS="Kursiv">
begin</EM>
 method of <EM CLASS="Kap-">
PhpTempt</EM>
 on the <EM CLASS="Kursiv">
doc</EM>
 block will be ignored even if the document root block has been entered explicitly with another call to <EM CLASS="Kursiv">
begin</EM>
.</LI>
<LI CLASS="Numeriert-n-n">
<A NAME="pgfId-997613"></A>The fully qualified name of the placeholder is</LI>
</OL>
<P CLASS="Programm-einzeilig">
<A NAME="pgfId-997621"></A>		doc.doc#PLACEHOLDER</P>
<OL>
<LI CLASS="Numeriert-n-n">
<A NAME="pgfId-997612"></A>Because application of <EM CLASS="Kursiv">
begin</EM>
 to the <EM CLASS="Kursiv">
doc</EM>
 block will be ignored, and the nested block <EM CLASS="Kursiv">
doc.doc</EM>
 can never be reached, the placeholder declared within that block will never be defined and thus the block will never actually be printed.</LI>
</OL>
<P CLASS="Haupttext-eingerueckt">
<A NAME="pgfId-997308"></A>Optionally, the parser may issue a warning if no block identifier has been specified in an <EM CLASS="Kursiv">
end</EM>
 tag.</P>
</DIV>
</DIV>
</DIV>
</DIV>
<HR>
<DIV CLASS="footnotes">
<DIV CLASS="footnote">
<P CLASS="Fu&szlig;note">
<SPAN CLASS="footnoteNumber">
1.</SPAN>
<A NAME="pgfId-999282"></A>You will find the examples of this tutorial and other sample templates and scripts in the <EM CLASS="Kursiv">
examples</EM>
 and <EM CLASS="Kursiv">
java-examples</EM>
 subdirectories of the <EM CLASS="Kap-">
PhpTempt</EM>
 root folder.</P>
</DIV>
<DIV CLASS="footnote">
<P CLASS="Fu&szlig;note">
<SPAN CLASS="footnoteNumber">
2.</SPAN>
<A NAME="pgfId-1002180"></A>It is assumed throughout this and subsequent chapters that you followed the installation instructions (<A HREF="tutorial.html#25534" CLASS="XRef">See Installation procedure</A> for more details).</P>
</DIV>
<DIV CLASS="footnote">
<P CLASS="Fu&szlig;note">
<SPAN CLASS="footnoteNumber">
3.</SPAN>
<A NAME="pgfId-998049"></A>You should not use dummy text placeholders within HTML's <EM CLASS="Kursiv">
input</EM>
 or title tags nor within HTML forms for the very same reason. If in doubt, try for yourself.</P>
</DIV>
<DIV CLASS="footnote">
<P CLASS="Fu&szlig;note">
<SPAN CLASS="footnoteNumber">
4.</SPAN>
<A NAME="pgfId-999026"></A>This is meant to help you identify logical contradictions within the structure of a template.</P>
</DIV>
<DIV CLASS="footnote">
<P CLASS="Fu&szlig;note">
<SPAN CLASS="footnoteNumber">
5.</SPAN>
<A NAME="pgfId-999944"></A>Note however that nested blocks with the same name, <EM CLASS="Kursiv">
doc</EM>
, are possible, provided that they do not have the document root block as parent (<A HREF="tutorial.html#35548" CLASS="XRef">See Known Bugs</A> for additional information).</P>
</DIV>
<DIV CLASS="footnote">
<P CLASS="Fu&szlig;note">
<SPAN CLASS="footnoteNumber">
6.</SPAN>
<A NAME="pgfId-1004107"></A>In this case, of course, both of them.</P>
</DIV>
<DIV CLASS="footnote">
<P CLASS="Fu&szlig;note">
<SPAN CLASS="footnoteNumber">
7.</SPAN>
<A NAME="pgfId-1000429"></A>Another, more imperative, reason for the use of placeholders will be given in paragraph <A HREF="tutorial.html#65722" CLASS="XRef">See Relative paths in recursive templates</A>.</P>
</DIV>
</DIV>
</BODY>
</HTML>
Return current item: Phptempt