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 Basic PHP Website (2018) Adding a Basic Form Objects and Email Validation

Ruiqi Mao
Ruiqi Mao
16,675 Points

why include is the better method to include file containing HTML snippets?

why include is the better method to include file containing HTML snippets?

comparing to 'required_once'

1 Answer

Tim Knight
Tim Knight
28,888 Points

Hi Ruiqi—

This is actually discussed a bit in the video just before the quiz. Check out the Using a Third-party Library again around 1 minute and 30 minutes into the video. Really it's about error reporting and how often the file can be included. With HTML snippets you may be looping over a snippet and need to include the file more then once or the snippet might not be a priority so you don't want the application to throw a hard error and stop just because it can't find the file.

Ruiqi Mao
Ruiqi Mao
16,675 Points

Hi Tim,

Thanks for your explanation! I rewatched her video and she did mention that to use include for html snippets; Can you tell me more about the situation "looping over a snippet"?

Tim Knight
Tim Knight
28,888 Points

Think about having a product snippet that contains all of the HTML to output a product summary on the page. Then using a for loop you could loop through all of the products in a query result and then using an include just include the file within the loop to put the product details.

Ruiqi Mao
Ruiqi Mao
16,675 Points

Got it! tho I haven't learned that far to have hands-on experience with looping over a html, but I can imagine the situation you just described! Thank you very much!