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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.