Page 1 of 1

includes

Posted: Thu Jul 28, 2005 6:35 am
by rsmarsha
I work on a website which uses an index template with a content area. A content file holds a list of variables like:

if ($page=home) include 'home.php';

then home would be pulled into the index content area.

The other way would be having a header,footer and nav bar, pulled into each page, which would be the best? Does the first way make the site any slower? As if not it's much easier to keep it that way than change all the files.

Posted: Thu Jul 28, 2005 7:23 am
by shiznatix
includeing a page like that is very common and it wont slow anything down

Posted: Thu Jul 28, 2005 7:28 pm
by harrisonad
I usually have a function named getContent() for static pages or getScript() for dynamic ones written on those includes. This I can include its contents to my HTML string.

Code: Select all

include "includes/nav_functions.php"
// ...
include "contents/home.php"
$bodystr = "
<body>
<table>
<tr><td>".getNavMenu()."</td></tr>
<tr><td>".getContent()."</td></tr>
</table>
</body>";
// ...
echo $headstr.$bodystr;

Posted: Fri Jul 29, 2005 2:28 am
by rsmarsha
Thanks for the replies.

I'll stick to the content file with the page includes in. Would it be better to use a switch block for the $page variable? I know switch will break when it finds a match.

Just wondering as the content gets fairly large after a lot of pages are added. :)

Posted: Fri Jul 29, 2005 3:28 am
by s.dot
switch or a bunch of if's
it's your preference

If the coding is quite lengthy switch may be best