The mgiGet Tag

Tag Behavior

Use the mgiGet tag to display the value of a page or site variable (see also mgiSet). Variables are containers for text, numbers, calculations, results, etc. that can be used after they are created (i.e., set) throughout a single page (page variables) or throughout an entire web site (site variables).

Tag Syntax

The mgiGet tag has one required parameter and seven optional parameters. The tag form is:

<mgiGet name="Name" scope="Page/Site" defaultValue="Text"
mode="Function" delimiter="String" odbcDatasource="Source Name"  
odbcUsername="Name" odbcPassword="Password">

Required Parameters:

  • name - The name is the name of the variable to display. Variable names are unique within a scope. If you include the mode parameter, the name parameter is not required.

Optional Parameters:

  • scope - The scope is the type of variable to display. "Page" variables are available to display from the location they are set on a page to the end of the page. "Site" variables are available to display after they are set on any page in a web site. The default scope is "Page".
  • defaultValue - The defaultValue is the text that displays if the variable is not found or if the variable is blank. If a default value is not specified, an empty string (blank) is displayed.
  • mode - The mode is the function that the mgiGet tag performs. In "returnAllNames" mode, the names of all variables from the specified scope are displayed. In "returnAllValues" mode, the values of all variables from the specified scope are displayed. In "returnAll" mode, the names and values of all variables from the specified scope are displayed in the format below. If you include the mode parameter, the name parameter is not required.
      Name1: Value1
      Name2: Value2
      Name3: Value3
      NameX: ValueX
  • delimiter - The delimiter is the character (e.g., "_", tabs, etc.) that is used to separate the names and values in returnAllNames, returnAllValues, and returnAll modes. The default delimiter for the "returnAllNames" and "returnAllValues" modes is a comma . The default delimiter for the "returnAll" mode is a carriage return and line feed (CRLF). In order to use special reserved characters such as tabs and backslashes as delimiters, you must use the appropriate Escaped String format.
  • odbcDatasource (NT only) - The odbcDatasource is the name of datasource on the server that provides access information for an external ODBC database. If the odbcDatasource parameter is included, site variable information will be stored in the specified ODBC database rather than the internal MGI database. Inquire with the server administrator for additional information about the use of ODBC databases. If you include the odbcDatasource parameter, the odbcUsername and odbcPassword parameters are required.
  • odbcUsername (NT only) - The odbcUsername is the username required to access the ODBC datasource. The odbcUsername parameter is required if you include the odbcDatasource parameter.
  • odbcPassword (NT only) - The odbcPassword is the code required to access the ODBC datasource. The odbcPassword parameter is required if you include the odbcDatasource parameter.

Example Usage and Output

Page Variable

<mgiSet name="QuizScore">
<mgiMath resultPrecision="1">
<mgiPostArgument name="Question1">
+<mgiPostArgument name="Question2">
+<mgiPostArgument name="Question3">
+<mgiPostArgument name="Question4">

Your quiz score is <mgiGet name="QuizScore">

Variables are so versatile that you could use them in combination with almost any other MGI tag. In this example, a student answers a simple 4 question quiz in a form. The result of a quiz score is calculated and set in a page variable. The mgiGet tag is then used to display the quiz score from the page variable to the student.

Site Variable

Now serving <mgiGet name="Subscribers" scope="Site"> 
Subscribers! Join us today!

Once they are set, site variables can be displayed on any page in a site. In this example, the number of subscribers to an online service is update during each subscription and set in a site variable named "Subscribers". This information is then available to display anywhere on the site using mgiGet and the scope parameter.


<mgiLoop itemList={mgiGet mode="returnAllValues"}>
  <mgiSendMail to="&mgiLoopIndex;" from="" 
  subject="Sale" mailserver="">

  Dear Customer,

  Shop our store during the month of October 
  and save 10% off all new fall merchandise!


In returnAllNames and returnAllValues mode, you can easily create a loop to perform a function on each name or value. In this example, a list of email addresses have each been set in a variable after a search. The comma-delimited list of variable values is then embedded in a loop that emails a form letter to each address.

<mgiGet mode="returnAll" scope="Site">

In returnAll mode, the variable names and values are formatted with colons in a list. This feature is useful for debugging purposes because you can display a comprehensive list of variables rather than listing an mgiGet tag for each variable. In this example, the site variables would display in this format:

Header: Fall is here. See our selection of 
winterizing products.
Phone: 667-223-4567
Version: 2.4

Suggested Usage

  • Storage of Information
  • Combining Information from Multiple Sources (Post Arguments, Path Arguments, Variables, etc.)
  • Embedding

[Understanding MGI Menu] [Using MGI Menu] [Referencing MGI Menu]

[MGI Guides Main Menu] [User Guide Main Menu]