☰ MenuCode Cobber

The Blog


Using includes

One of the most effective and efficient approaches for developing a website is the use of headers and footer includes. The principal behind the use of headers and footer includes is one of simple code reuse that eliminates duplication of content while simultaneously reducing any errors.

So what do we mean by includes and code reuse?

Imagine you have three web pages and each page has the same menu at the top of each page and the same content at the base of each page. It doesn't make sense to copy and paste the same code in each page does it. Instead of replicating the same content on every page, we create one additional content area for the header and footer. This will hold the content (one for the footer and one for the header).

It may sound a little confusing at first but in essence the principle is simple. Have one piece of code that can be used in multiple web pages. The beauty behind includes is one of reduction of time and potential data irregularities. In relation to the header, if you edit the header in the new include file then that change will appear on all other web pages that use the header include. 

So, in the case of the header menus mentioned earlier, we place the header content (header menu) into the new page and call it header. Normally this page is held in a folder called 'includes'. The same process is repeated again for the footer. Now you have a folder called 'includes' which contains two files . . .one for the header content and the other for the footer content.

The next step involves removing the existing content from the top and bottom of each webpage and adding a small piece of code in it's place. The small piece of code allows the website to fetch and include the content of the new files (in this case the new header and footer) and include it into each page. Apart from removing any duplication of website content through the use of header and footers, the use of includes also reduces any potential for incorrect content within the website.

 

<< Go back to the previous page

Please help spread the word