RE: [PHP Template] Template Discussion

[email protected] ("Peter Kocks") Wed, 22 Mar 2000 13:43:29 -0800
Newsgroups php.template
Message-ID <[email protected]>
>
> The way you suggest doing it
> ----------------------------
> <? for($loop=0; $loop<=count($Name); $loop++): ?>
>   <? print $Name[$loop]; ?><br>
>   <? print $Address[$loop]; ?><br>
>   <? print $Phone[$loop]; ?><p>
> <? endfor; ?>
>

No I propose using here docs to make this simpler.

<? for($loop=0; $loop<=count($Name);
op++){ 
	print <<< ADDRESS;
		$Name[$loop]<br>
		$Address[$loop]<br>
		$Phone[$loop]<p>
ADDRESS;
	} 
?>

Of course you could use the foreach call, which although undocumented, I believe is available in php4.

And, a simple addition to the language of a template(filename) function that would add a here doc in the same way as an include does today.

So the programmer would write:

<? for($loop=0; $loop<=count($Name); $loop++){ 
	template("address.tmpl");
} 
?> 

Add the designer would write the file called address.tmpl:

		$Name[$loop]<br>
		$Address[$loop]<br>
		$Phone[$loop]<p>

Note that function call could be added to the template file that the designer writes by using object methods.  As in:

		$Name[$loop]<br>
		$Address[$loop]<br>
		$Phone[$loop]<p>
		{$orders.table()}