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 PHP Basics (Retired) PHP Conditionals & Loops Foreach Loops

Joseph Casey
Joseph Casey
6,782 Points

A source covered in <?php?> seems awful impractical.

Is there something that is found in later lessons which can substitute for the heavy usage of opening and closing php scripts everywhere? Something about that seems off, but I'm not sure what it is.

2 Answers

Robert Komaromi
Robert Komaromi
11,926 Points

The only alternative is to not use PHP in your templates, or try a PHP templating engine like Twig or Blade. Also, you shouldn't be doing any logic in your templates / HTML documents with PHP. You should use it for conditionally displaying something, iterating through a list to be displayed, showing specific variables (ex. a username), etc.

Ian Hudson
Ian Hudson
13,457 Points

Joseph,

I just started to study "MVC Frameworks for PHP". Among other things, this helps to organize your code and cut down on redundancy as well. The following link may explain what it is, and how/why its used.

http://www.htmlgoodies.com/beyond/php/article.php/3912211

Hope that helps,

Ian