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 trial

PHP Build a Simple PHP Application Creating the Menu and Footer Including the Footer and Adding Additional Pages

Why was </div> at the starting of header.php and in the end of footer.php?

In this video it shows that the tag </div> was at the starting of header.php and at the bottom of footer.php.

1 Answer

This section of the lesson is teaching how to construct a PHP layout template using sections or 'partials'. Think of these like pieces of an HTML page that will be reconstructed by the server to present the page. That means the each section will need to build it's portion of the HTML:

/*
 :: Your Web Page::
-------------------------
|                       |
|    Header.php         |
|                       |
-------------------------
|                       |
|                       |
|   Content.php         |
|                       |
|                       |
-------------------------
|                       |
|   Footer.php          |
|                       |
-------------------------

*/

So the < / div> you are seeing in some places like the footer are actually closing div elements from the template above it.

The reason for this is that there are many parts of an HTML page that remain the same. Really all that changes is the content. SO for things like the navigation bar (as an example); why write the nav bar for every page in the site when it is always the same? That is why you template, so that you reuse the navbar code and dont have to repeat yourself. The benefits to this are more apparent when you have a multi page site. Lets say you have 50 pages in your site and you did not template. If you need to change the title of one of the links in the navigation, you are going to have to make that update to 50 files. If you use templating then all those pages are reading from one single nav.php file. You can make one single change and all pages will reflect the update. Common parts of the page to template out are the header, footer, sidebar, and navigation, however this lesson just shows the header and footer being templated.

Does this help?