View Full Version : How to Loop a Template?

01-04-2006, 12:47 AM
I have a template that has mostly HTML and some data from php in form of <?=$text;?>. I have a page that need to have the content with same format (the format in the template) with different data. How can I loop the template couple time in the web page? I try to reuse the template, not create a string of the content of the same template and then echo them.

Many thanks.

01-04-2006, 01:12 AM
I don't quite understand. You mean like your template with all the content, and then it again underneath it without? A picture may help me.

01-04-2006, 02:16 PM
Usually you would have your template split into include files.
Header, menu, footer etc.

If you have them in variables then you could do something similar to

$head = '<table width="80%" border="1" align="center" cellpadding="2" cellspacing="0"><tr><td>';
$foot = '</td></tr></table><br>';
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>

<table width="80%" border="1" align="center" cellpadding="2" cellspacing="0">
for($x=0; $x<5; $x++){
echo $head;
echo 'This is box number ' . $x;
echo $foot;