Webpage PHP Modules

After a few months of developing my web development skills, I slowly realized how messy and intricate webpage files can get. This fueled to my desire toward finding cool ways to manage a webpage’s organization.

Now each webpage consists of multiple modules such as the navigation bar, header wraps, various content, and the footer:

I discovered from a blog post by Kenny Luong that creating PHP modules allows pages to utilize modules that have one dependency. I use this method on my personal site joshuatrivera.com by converting pages from .html to .php

Here is a snippet of my cumbersome navigation bar at the beginning of all my pages.

<div class="navbar navbar-default navbar-fixed-top" role="navigation">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="index.php">JTR</a>
    </div>
    <div class="navbar-collapse collapse navbar-right">
      <ul class="nav navbar-nav">
        <li class="active"><a href="index.php">HOME</a></li>
        <li><a href="resume.php">RESUME</a></li>
        <li><a href="http://doswah.com">BLOG</a></li>       
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown">PROJECTS <b class="caret"></b></a>
          <ul class="dropdown-menu">
            <li><a href="micromouse.php">MICROMOUSE</a></li>
          </ul>
        </li>
      </ul>
    </div>
   </div>
  </div>

I placed this snippet as a .php file in a folder of modules. Now to include the navigation bar in my index.php page, I just need to have:

That’s it. Pretty awesome to me. This method helps my pages become modular and makes reading my webpage code easier for me. If it doesn't work at first, remember to rename both your module snippet and webpage to a .php file!