soycharliente Posted March 16, 2008 Share Posted March 16, 2008 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 More sharing options...
JD* Posted March 16, 2008 Share Posted March 16, 2008 depending on how you are formatting it, why not just include the same navigation twice, but wrap it in a different div tag and use css to style it differently? Link to comment https://forums.phpfreaks.com/topic/96414-solved-nested-includes/#findComment-493428 Share on other sites More sharing options...
redarrow Posted March 16, 2008 Share Posted March 16, 2008 try <?php require_once("the_page.php"); ?> Link to comment https://forums.phpfreaks.com/topic/96414-solved-nested-includes/#findComment-493459 Share on other sites More sharing options...
soycharliente Posted March 17, 2008 Author Share Posted March 17, 2008 <?php require_once("the_page.php"); ?> I don't understand how to apply this. Link to comment https://forums.phpfreaks.com/topic/96414-solved-nested-includes/#findComment-494011 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.