Jump to content

[SOLVED] Nested includes


soycharliente

Recommended Posts

This thread has two "questions" to it. I'm going to lay out the situation and then pose the questions.

 

-= Relevant code =-

index.php:

<body id="home">

<?php include($_SERVER['DOCUMENT_ROOT']."/lib/header.php"); ?>

<div id="main">

<div id="nav">
<?php include($_SERVER['DOCUMENT_ROOT']."/lib/main-nav.php"); ?>
</div> <!-- [END nav] -->

<div id="content"></div> <!-- [END content] -->

<?php include($_SERVER['DOCUMENT_ROOT']."/lib/footer.php"); ?>

</div> <!-- [END main] -->

</body>

 

lib/main-nav.php:

<?php
echo <<<DELIMETER
<a href="#">Link</a>
<a href="#">Link</a>
<a href="#">Link</a>
DELIMETER;
?>

 

lib/footer.php:

<?php
echo <<<DELIMETER
<div id="footer">
Witty sentence about something will go here.
<br />
<a href="#">Link</a>
<a href="#">Link</a>
<a href="#">Link</a>
</div> <!-- [END footer] -->
DELIMETER;
?>

 

1. The navigation in lib/main-nav.php is the same as the navigation in lib/footer.php as you can see. What's the best way to simply include lib/main-nav.php inside lib/footer.php so I can just reuse that code. That way I don't have to update the navigation in multiple places and by updating in one place it will automatically change in any other place I have it. Is this the best way?

lib/footer.php:

<?php
echo <<<DELIMETER
<div id="footer">
Witty sentence about something will go here.
<br />
DELIMETER;

include($_SERVER['DOCUMENT_ROOT']."/lib/main-nav.php");

echo <<<DELIMETER
</div> <!-- [END footer] -->
DELIMETER;
?>

 

2. Is there a better way to do this than with "nested includes" because it just seems sloppy and unorganized.

Link to comment
https://forums.phpfreaks.com/topic/96414-solved-nested-includes/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.