Template question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ccjob2
Forum Newbie
Posts: 16
Joined: Tue Jun 04, 2002 9:37 am

Template question

Post by ccjob2 »

I'm working on a site with a template system. I wish create 5 blocks: header, footer, body, left and right, that contain severals code.
The problem is that when I include header.html (for example) and footer.html the page is OK. But when I include also left.html (or right.html) the body.html content is displaied under left.html.
How can I display: the left.html, the body.html and the right.html all on the same row.
I tried with tables, but I don't know how to insert php content into a table definition.
Can you help ?

Thanks
Carlo
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Try:

Code: Select all

<?php
include 'header.php';
echo <<<END
<table width="100%" cellpadding="5" cellspacing="0" border="0">
<tr>
	<td width="20%">
END;
include 'navleft.php';
echo <<<END
	</td>
	<td width="60%">
END;
include 'content.php';
echo <<<END
	</td>
	<td width="20%">
END;
include 'navright.php';
echo <<<END
	</td>
</tr>
</table>
END;
include 'footer.php';
?>
Obviously change table properties (cell widths etc.) and include file names to suit yourself.

Mac
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Just a little more

Post by BDKR »

One question if. Are all of those includes actually different files?

If so, then each time a page loads, the server has to do an individual disk read for each of those include files. That's extremely inefficient! :(

However, if you make a file called html.php and convert each of those include files to functions that reside in html.php, then there is only one disc read that needs to be done.

Code: Select all

<?php

# This used to be header.php
function header()
    &#123; 
    /* header stuff */
    &#125;

# Once was navleft.php
function navleft()
    &#123;
    /* navleft stuff */
    &#125;

# And so on and so on

?>
Hope that helps.

Later on,
BDKR (TRC)
ccjob2
Forum Newbie
Posts: 16
Joined: Tue Jun 04, 2002 9:37 am

What is END ?

Post by ccjob2 »

I don't know <<<END istruction (nor END;). Anyway Thank you very much for your helps.

Carlo
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

All that the echo <<<END does is say to PHP parse this lot until you reach END;. Stuff echoed like this retains its formatting which can help with debugging HTML code. There's also the fact that you don't have to worry about escaping quotes (double or single). Personally I find that it's a method that works well for large blocks of HTML code with some PHP variables interspersed.

There's a bit of information about it in the manual as well (check the examples section):
http://www.php.net/manual/en/function.echo.php

Mac
Post Reply