Virtual Include tutorial submitted by Cesar Cainelli

Welcome to your one-stop look at the virtual include function. Contrary to popular belief, this is actually a very simple function, and was taught to me over an instant messenger. This function can streamline dozens, even hundreds of lines of code via a single line, and save you precious server space as well. (Oh, and it gets rid of the need to constantly copy and paste, too!)

Let's start with the all-important line itself, the external call. For the sake of the tutorial, we will call to a navigation page (often the most useful purpose of the include function). Note that this call will work for everything from headers to footers. I personally copy/paste the footer on each of my pages, but if you have a more complex footer, this is definitely a good code to implement. Insert this line in place of where you want the information in the external file to go:
<*!--#include virtual="nav.html"--*> For display purposes, I have had to insert asterisks (*) into the code.
REMOVE THEM when using this code.

It is important to copy the code exactly as is, with the exception of the actual page you are calling. For Argentos Online, I build the pages within a table; the left column includes the call to the nav.html file, and the right column includes any other information on the page.

REMEMBER, if the page you are currently coding is within a folder, your code will have to call up to the origin! For example, this specific page includes THIS code in the left column:
<*!--#include virtual="../nav.html"--*> Again, remember to remove the asterisks displayed in the code.

Now, I'm sure you're wondering what sort of information you need to include in the html file you're calling to, right? This is also quite simple. It needs to be a full html page so that it can be processed by the browser, but the information included within it can be quite minimal if you prefer. For this final example, I will remove the bulk of the code in my nav.html file, as all that's needed for this example is a basic idea of how to build the page you are calling to.
<html> <head> It's probably best to leave this empty unless the information in your header is essential for use within the html file you are creating. </head> <body> {{ THIS IS WHERE ALL OF MY NAVIGATION CODE GOES }} REPLACE THIS TEXT WITH YOUR OWN: Navigation, headers, footers, whatever you need! </body> </html> And that's all there is to it! Quite simple, no?



ArgentosOnline is © 2006, Cesar Cainelli.
All design, unless stated otherwise, is by Cesar Cainelli.
Argentos Online staff can be reached at webmaster@argentosonline.com.