Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMichael Thomas
10,910 PointsWhy have an opening div tag at the bottom of header.php?
When we copy and paste the header from index.php to header.php why are we copying this opening div tag
<div id="content">
It feels more intuitive to leave this out because when I or someone else is working on index.php it may not be immediately apparent that the opening div tag at the top is actually at the bottom of our header.php.
Is this just an accepted best practice? If so then fair enough! Just seams weird to me.
Thank you.
Michael Thomas
10,910 PointsThanks Scott if you see this. I can't respond to your comment or select it as the best answer, but thank you!
3 Answers
Scott Peake
17,052 Points<i>Sorry Michael, I always post my answers in the wrong spot... talk about being sloppy...</i>
Honestly, not sure why he did it that way, but it really doesn't matter when using php include(). This is since the include(), if coded properly, would seamlessly fit into the flow of the HTML document.
I think your intuition is correct... this can easily cause confusion! Personally, I think it would be best to have that at the TOP of the code so when I saw it, I would know exactly where I was.
My code is often sloppy (a lot of testing and "commenting out stuff") so when it comes to inserting php code I make sure that there aren't any "danglers." As he showed in one of the videos, a SIMPLE mistake in php code context and everything goes awry!
Keep up the good work!!!
Rifqi Fahmi
23,164 PointsThanks bruh :)
Rifqi Fahmi
23,164 Pointsare we have to type the closing div tag too?? for each different pages?
Scott Peake
17,052 PointsHey there!
Yes, there will need to be a closing tag (for HTML continuity), but it's location may, or may not, be in these partials.
Each partial page (header.php, footer.php, etc.) does NOT have to "pass" the HTML continuity test with matching opening and closing tags. This is because the partial isn't intended to run on its own. It's only when the PHP include() method is run, and they are pieced together as one HTML document, that it becomes important.
Something I do to make sure I am not messing up the continuity is temporarily "comment out" sections of my code that I am replacing with the PHP partial. Only once I have successfully tested the PHP processes on the server I remove those commented sections. I also highly recommend using GitHub for version control if you are working on more complex pages with lots of PHP.
Keep up the good work buddy!!!
Scott Peake
17,052 PointsScott Peake
17,052 PointsHonestly, not sure why he did it that way, but it really doesn't matter when using php include(). This is since the include(), if coded properly, would seamlessly fit into the flow of the HTML document.
I think your intuition is correct... this can easily cause confusion! Personally, I think it would be best to have that at the TOP of the code so when I saw it, I would know exactly where I was.
My code is often sloppy (a lot of testing and "commenting out stuff") so when it comes to inserting php code I make sure that there aren't any "danglers." As he showed in one of the videos, a SIMPLE mistake in php code context and everything goes awry!
Keep up the good work!!!