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 trialAustin Herron
Courses Plus Student 990 PointsAdding opening div tag in header.php with no closing.
I really don't think it is a good idea to include the <div id="content"> tag in the header.php template as it is easy to forget to add the closing tag in each file, even in this video the instructor forgets to terminate the div inside suggest.php and catalog.php. Not to mention, the content div tag is not even a part of the website header, which should only be the navbar and a logo / title, it is part of the website content body.
Those reasons aside, inside workspaces it is impossible to just create a closing div tag. You have to type out an opening div tag which creates the closing div tag, then delete the opening tag only leaving the closing.
So, are there any reasons to keep the opening div inside the header.php template as opposed to adding the <div id="content"> to each file?
2 Answers
Kevin Korte
28,149 PointsYes, one bigger reason to do it this way, is the DRY principle. Don't-Repeat-Yourself. The problem if you put the <div id="content">
into each page template, is what happens if you forget to add that div to each file, or even more common, 6 months down the road you want to add a class, or an attribute to your content div. Will if you did it the way taught here, you only have to modify this in one place. If you put it into every single file, you have to copy and paste it to each file. What it your site has 80 template files. Yuck.
Also, if you watch closely, she's not closing the div in contact.php or suggest.php. She's closing the div in the footer, so as long as you include your header and footer files, you know for certain that div is going to be opened and closed, and the content of the files will be neatly wrapped in the content div.
In regards to wordpress making you create a div and delete half of it. Not the end of the world, but even more reason to do it this way. You only have to go through that once, not once for each file you create...again, yuck.
Hope that makes sense, but the way that is shown in the video is a better practice to follow.
Brian DuPont
30,448 PointsHi Austin, The closing tag for <div id="content"> was placed into the inc/footer.php file, so now you don't have to remember to add the closing div tag to each file.
Austin Herron
Courses Plus Student 990 PointsAustin Herron
Courses Plus Student 990 PointsThis was supposed to be a question for this video,
https://teamtreehouse.com/library/build-a-basic-php-website/building-a-media-library-in-php/including-the-footer-and-adding-additional-pages
However I guess i placed it here somehow.