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

General Discussion

Philip Bradbury
Philip Bradbury
33,368 Points

Website templates PHP or HTML?

Hi all,

Im currently learning the PHP side of treehouse and I'm just wondering about site templates and whats done in the real world. This route shows using PHP for templates but looking at code on website in the real world they don't use PHP they just use HTML. I used to use dreamweaver to do my code and they had template tags, is this the way its normal done in the industry?

Thanks

Phil

4 Answers

Kazimierz Matan
Kazimierz Matan
13,257 Points

I have made some websites using Smarty template engine. It pretty well cooperates with PHP and, in my opinion, is easy to use. It offers features useful for designer as well as for programmers. Some say it it a little to "heavy", but I have never experienced.

I think this could be considered preferential, but I would highly suggest that you standardize and always go with php. Firstly they will consistently be more flexible than html files. Secondly, they are consistent file types. Do you want to be trying to remember which files are html and which files are php as you develop an website? Probably not. There is no conceivable advantage to having either HTML files and/or a mixed bag of file types, so why bother?

I think you'll find as you grow as a developer you'll strive for consistency in your development techniques. camelCase vs. snake_case, pluralizing nouns, capitalization, placement of link tags vs. script tags, etc. etc. As projects grow in scope it's important for you as the developer to have a set frame of your practices to assist you in building and supporting you projects. This is perfect example of one of those parameters. "I always use php files, so I never have to go and check what the file type is when creating links, etc. It saves me 2 - 3 seconds every time I put in a link. Marginal, but as the project grows it's a substantial savings of time and mental resources. It also helps when another developer is working on my code."

IMHO.

Chris Howell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,702 Points

Hi Phil, So I read this and the line where you said "..in the real world they don't use PHP they just use HTML". That caught my eye and I felt the need to elaborate a little on some basics of PHP because from that line I am thinking that you are opening web pages and "view the source code" then you are under the impression that PHP is non-existent. This is not true. PHP is a ninja, you never see it but it is always there. ;)

As you will begin to understand as you work your way through the PHP courses. PHP is a server-side language. Which basically means the web server that a website is running on handles the PHP code before it ever reaches YOU (the person browsing). You can go to any website you like, view the source code and all you will ever see in there is HTML. HTML, CSS, and maybe some javascript because these are the things that the Browser knows how to read and display. A web server knows how to read and deal with PHP.

Your web browser doesn't care about PHP, it wouldn't know what to do with it. Like Apache(the web server) could care less about how to display HTML to YOUR browser. I hope that makes sense. There are ALOT of sites that have PHP back-ends. especially if they are running something like Wordpress.

As for templates though, that is a whole book of its own. I am not sure how to give you an answer for that as it was general but if you get more specific with your question about templates I can try and see if i can help.

Philip Bradbury
Philip Bradbury
33,368 Points

Hi thanks for all your input. Chris thats it i total forgot that when i view source code the PHP is server side and it will just bee shown as HTML and not the actually PHP including the HTML.

Jesse that does make sense as a designer first i know how all the small things done a million times add up so knowing how to do that 'small thing' the most efficient way can save minutes/hours through out a project.