Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP

Bill Chung
Bill Chung
945 Points

Understanding PHP includes and what they should contain

I'm just reviewing Randy's PHP section on includes (video: "Including the Header") and in the example on includes, he copies a portion of index.php file which contains the html <head> and header div and pastes it into header.php. However, the include for header.php also includes the opening tag for the next div (in this case it's #content).

Intuitively, I wouldn't think to copy the opening tag of the next div. What is the reasoning here and what are the consequences of NOT including the opening tag of the next div?

2 Answers

J.T. Gralka
J.T. Gralka
20,126 Points

Bill,

Ostensibly, you would have a footer.php file that you would include at the bottom of your page that might begin with the closing div to your content div tag. In general, I'm not a fan of doing it this way, but all developers are different, and the way Randy does it in this example isn't wrong.

Remember the reason for using include files: they keep us from having to keep writing code over and over and over again from one file to the next. All of the pages on our website would need to contain a content div, and so, it isn't a bad idea for us to include the opening part of the content div tag in the header.php file.

Does that clarify things for you?

Best,

J.T.

Bill Chung
Bill Chung
945 Points

Absolutely it does. When you put it that way, it does make sense to include the opening tag of the content div.

Thanks JT