#11: Working Modularly with PHP

Many sites do not use any fancy Content Management System (CMS) to generate their pages, they are just just good ol' static HTML content. A site for your grandmothers pie baking business probably only has a few pages, perhaps a homepage, about page, and contact page. Each of these pages has different main content, but much of it stays exactly the same, like the header, navigation, and footer. Think of these sections as "modules" that you can easily use PHP to insert into the page. This way, making changes to those sections changes all the pages at the same time, saving you time and potentially mistakes. At the end, I show you how you can still achieve unique effects in your navigation despite the code being identical.

Yes you can tell (at 6:10 of the video) that the html code was inserted via php. The way you indent and space your code is unique and you wouldn’t make a simple html indentation mistake like that had it been in an html file and not included using php. A way to fix that, depending on how your organizing your code, would be to use the same spacing as you would a normal html file. So your paragraph tag would a have a couple tab indentations in the header.html file, but your heading tag is fine because php includes the file right where you put the php include statement with the spacing.
I hope this makes sense. I’m enjoying your screencasts very much! Keep it up Chris.

Posting Code!

You may write comments in Markdown. This makes code easy to post, as you can write inline code like `<div>this</div>` or multiline blocks of code in triple backtick fences (```) with double new lines before and after.

Code of Conduct

Absolutely anyone is welcome to submit a comment here. But not all comments will be posted. Think of it like writing a letter to the editor. All submitted comments will be read, but not all published. Published comments will be on-topic, helpful, and further the discussion or debate.

Want to tell us something privately?

Feel free to use our contact form. That's a great place to let us know about typos or anything off-topic.