Tags for this article: advice, help, html, include, javascript, php, tutorial, website
If you have surfed Web for the whole day, in the Websites you will notice that almost all the Websites have themes for their site’s design and this design will be repeated across all the pages of that particular Website. On any of the Web design Website, there are lots of elements that will be repeated in many ways including left navigation and the header portion of that particular page.
When you write an article everyday, you don’t need to write HTML to add some of the standard elements. All you want to do is to write articles. The templates that are needed will be built by “content management tool and if you do not have the access to this tool, there are several ways to manage your Website without editing each and every page by hand.
What are includes?
In HTML, an include section is not just an HTML document itself but it is just a portion of another page and using programming these can be included in your complete Web pages.0020unofrtunately this is supported by HTML. So, you will require some type of scripts or programs to add your include files in to your pages. Most of the include files are the things that are repeated on several pages of a particular Website without changing the things like navigation, contact notices and copyright information.
“Server Side Includes”
SSI was the first one to be developed that allows the Web developers to include all the HTML documents in to another page. If at all your Web server supports SSI, you can easily create templates for your Websites.
Firstly, you have to save HTML for all the common elements of your Website as a separate file. For example: you can save your navigation files as navigation.ssi or as navigation.html.
Secondly you have to use SSI tag to add that HTML in each page of your Website. The SSI tag is “#include virtual” = “Path to File/include-file.html”.
Thirdly, you can use the same tag in all the pages which you want to include.
“PHP”
PHP is another level of server programming language. This language will let you to include all of your HTML documents in another page. This language is much like SSI. This PHP is also a Server level language like that of SSI. In order to add pages using PHP you have to follow these steps
Firstly, you have to save all your files separately in another document. For example: your navigation files can be saved as navigation.php or navigation.html.
Secondly, use this PHP code to include the page. The code is
<? Php
require ($DOCUMENT_ROOT. “Path to file/include-file.html”) ;?>
Thirdly, use the same code with each page to add your file.
“ASP”
ASP or “Active Server Pages” is just another way to add your files in another page. The method is same as PHP but the code is different. The code is
“#include file=”path to file/include-file.html”
JavaScript
This is also another way to add your files into another file. But this does not require server level programming. This is little bit complicated compared to other server level includes.
Firstly, you have to save HTML common elements in JavaScript style. In this file, any HTML written should be printed with the “document, write”.
Secondly you have to use the code “<script type=”text/JavaScript” src=”path to file/include-file.js”> < /script>”
Thirdly you can use the same code for including files in all the pages.