Help Search Campus Map Directories Webmail Home Alumnae Academics Admission Athletics Student Life Offices & Services Library & Technology News & Events About the College Navigation Bar
MHC Home Using the Document Interface
TopNext Page

Variables

A variable contains a value that gets substituted into your document whenever you reference its name from within a DI command. To insert a variable's value, its name is preceded with a $. For instance, $foo refers to the variable whose name is foo.

There are two main types of variables, internal and user-defined. Internal variables are created by the DI. They contain information such as the last time the document was modified and the current date & time. Most internal variables cannot be changed. User-defined variables are set by you and can contain anything you want them to. Both kinds of variable get reset every time a document is displayed.

The main command you use to create and change variables is the .SET command. Below is the output from the simplest version of the .SET command, which just displays all variables. The output is automatically done using the <PRE> paragraph tag:

<!--.set-->

BeginCenter   = <p align=center>
Count         = 7,480
CountLong     = This page has been accessed 7,480 times since March 13, 1998.
CountSince    = March 13, 1998
Date          = Mon Feb 13 12:36:55 EST 2012
DateFmt       = %c
DIVersion     = 20110111101326
DocName       = variables.shtml
EndCenter     = </p>
FileBase      = 
HasClientMaps = 0
HasFontSize   = 1
HasFrames     = 0
HasImageMaps  = 1
HasImages     = 1
HasTables     = 1
HTTPHeaders   = 
LastMod       = Tue Jun 11 11:28:27 EDT 2002
NewsMod       = 0
OnCampus      = 0
Referer       = 
SQLJavascript = <SCRIPT language="JavaScript">
<!--
var isNS4 = (navigator.appName=="Netscape")?1:0;
function DI_validate_text_key( event, okchars ) {
	var key = isNS4 ? event.which : event.keyCode;
	if( key < 32 || key >= 255 || key == 127 ) return true;	// control chars
	if( okchars.indexOf(String.fromCharCode(key)) < 0 ) return false;
	return true;
}
function DI_validate_text_blur( obj, label, places, min, max, blank ) {
	if( blank && obj.value=='' ) return true;
	if( isNaN(obj.value) ) {
		alert( DI_fieldname(label,'This field')+' requires a number' );
		return false;
	}
	var num = Number(obj.value);
	if( !isNaN(min) && num<min ) {
		alert( "The minimum value for "+DI_fieldname(label,'this number')+
			" is "+DI_zero_pad(min,places) );
		obj.value=num=min;
	}
	if( !isNaN(max) && num>max ) {
		alert( "The maximum value for "+DI_fieldname(label,'this number')+
			" is "+DI_zero_pad(max,places) );
		obj.value=num=max;
	}
	if( places>=0 ) {
		var p = Math.pow(10,places);
		obj.value = Math.round(num*p)/p;
		if( places>0 )
			obj.value = DI_zero_pad(obj.value,places);
	}
	return true;
}
function DI_zero_pad( num, places ) {
	var s = new String(num);
	if( places>0 ) {
		if( s.indexOf('.')<0 ) s += '.';
		while( s.length-s.indexOf('.') <= places )
			s += '0';
	}
	return s;
}
function DI_textarea_limit( obj, label, evnt, len ) {
	if( evnt && evnt.type=="keypress" ) {
		var key = isNS4 ? evnt.which : evnt.keyCode;
		if( key < 32 || key == 127 ) return true;
	}
	if( obj.value.length >= len ) {
		var msg = "There is a limit of "+len+" characters in "+
			DI_fieldname(label,'this field')+'.';
		if( obj.value.length > len ) msg += " \nYou have entered "+obj.value.length+" so far.";
		alert( msg );
		if( !evnt || evnt.type!="keypress" ) obj.focus();
		return false;
	}
	return true;
}
function DI_fieldname(label,alt) {
	return label!='' ? '"'+label+'"' : alt;
}
// -->
</SCRIPT>

To set a user-defined variable, use a variation of the .SET command, this time specifying a name=value. Let's illustrate another feature while giving an example:

<!--.set foo="My variable"-->
<!--.echo "foo is set to <B>$foo</B>"--><BR>
<!--.echo 'foo is set to <B>$foo</B>'-->

foo is set to My variable
foo is set to $foo

Notice that the second example did not do the same thing as the first. That's because the parameter passed to the .ECHO command had single-quotes around it. Variables contained within single quotes are never expanded. That way, you can safely use the $ character in a string without getting a syntax error.

Descriptions of Internal Variables

Variables
BeginCenter Depending on the browser, the method for centering a paragraph may be <CENTER> or <P align=center>. Use with $EndCenter.
Count The same as the .COUNT command without any arguments.
CountLong The same as the command .COUNT long.
CountSince The same as the command .COUNT since.
Date Today's date and time, using $DateFmt. See this page for a description of the format understood in $DateFmt.
DIVersion Version number for the copy of the DI currently running. This number always goes up with new versions, so if you know you are using a feature that will not work in a future version, you can make a comparison using > or <
DocName The filename (without any path info) of the document.
EndCenter Use to balance $BeginCenter.
HasClientMaps 1 if the user's browser supports client-side imagemaps.
HasFontSize 1 if the user's browser supports the <FONT SIZE=x> attribute.
HasFrames 1 if the user's browser supports framesets.
HasImageMaps 1 if the user's browser supports server-side imagemaps.
HasImages 1 if the user's browser supports images.
HasTables 1 if the user's browser supports tables.
LastMod The date and time the document was last modified.
OnCampus 1 if the user is viewing the page from an MHC Internet connection.
Referer Description of the page which referred to the current page. If the referring page was on the MHC system, the result is the full system path of the file. Otherwise it is full URL (with http://servername).

There are also several variables that have names beginning with db_ which are only created when a database has been used by a command in the current page.

Examples

Variables can be used to keep from having to type the same sequence in lots of places within a file. For example:

<!--.set me="Dan Wilga"-->
<!--.echo "If you really like $me, why not send $me some email?"-->

If you really like Dan Wilga, why not send Dan Wilga some email?

You can even use variables to hold long strings of information, including HTML code.

Variables can also be used with .IF to produce different results based on a value. Here, we are using the internal variable count:

<!--.if $count==1-->
   <!--.set msg="only one time :-("-->
<!--.elsif $count<100-->
<!--.set msg="only $count times."-->
<!--.else-->
<!--.set msg="$count times. Not too shabby!"-->
<!--.endif-->
This page has been hit <!--.echo "$msg"-->

This page has been hit only one time :-(

Another use of variables would be to have two blocks of HTML code, one which is presented to on-campus users of the page, another off-campus:

<!--.if $oncampus-->
   <P>You're on campus
<!--.else-->
   <P>You're not on campus
<!--.endif-->

You're not on campus

CGI Variables

CGI variables, which are passed using an HTML form or by adding them onto the end of a document's URL, can be accessed using the .CGIVARS command.

The DI can also provide you with read-only access to any of the standard CGI environmental variables which are passed to the DI script by the Web server. This is accomplished by using the syntax $%VARNAME. For example, $%REMOTE_ADDR is the IP address of the site that requested the document. CGI environmental variables are an extremely advanced feature, and are beyond the scope of this document.

Database Variables

The final type of variable that can be used in DI scripts is database variables. These are created by the .DBHASH and .DBARRAY commands. Their contents can be echoed using the database variable syntax, or the .DBDUMP command. For more information on this topic, please refer to the pages on databases.

----------------------------------------
Top | Next Page

Home | Directories | Web Email | Calendar | Campus Map | Search | Help

About the College | Admission | Academics | Student Life | Athletics
Offices & Services | Giving | News & Events | Alumnae | Library & Technology

Copyright © 2002 Mount Holyoke College. This page created by the OIS Operations Group and maintained by Webmaster. Last modified on June 11, 2002.